-
Notifications
You must be signed in to change notification settings - Fork 9
/
BezelHUD.m
229 lines (177 loc) · 7.51 KB
/
BezelHUD.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
//
// BezelHUD.m
// BezelHUD
//
// Created by Julius Eckert on 20.01.08.
// Copyright __MyCompanyName__ 2008. All rights reserved.
//
// QS Interface template by Vacuous Virtuoso
//
#import <QSEffects/QSWindow.h>
#import <QSInterface/QSSearchObjectView.h>
#import <QSInterface/QSObjectCell.h>
#import "BezelHUD.h"
@implementation BezelHUD
- (id)init {
return [self initWithWindowNibName:@"BezelHUD"];
}
- (void) windowDidLoad {
[super windowDidLoad];
QSWindow *window=(QSWindow *)[self window];
[[self window] setLevel:NSModalPanelWindowLevel];
[[self window] setFrameAutosaveName:@"BezelHUDWindow"];
// If it's off the screen, bring it back in
[[self window]setFrame:constrainRectToRect([[self window]frame],[[[self window]screen]visibleFrame]) display:NO];
// How much the interface moves when it's showing / hiding
// Tip: set "hide offset" = -"show offset" so the window doesn't gradually get displaced from its original position
[window setHideOffset:NSMakePoint(0,0)];
[window setShowOffset:NSMakePoint(0,0)];
[window setShowEffect:[NSDictionary dictionaryWithObjectsAndKeys:@"QSBingeEffect",@"transformFn",@"show",@"type",[NSNumber numberWithFloat:0.09],@"duration",nil]];
[window setHideEffect:[NSDictionary dictionaryWithObjectsAndKeys:@"QSShrinkEffect",@"transformFn",@"hide",@"type",[NSNumber numberWithFloat:.13],@"duration",nil]];
// setWindowProperty returns an error, unfortunately... ignore it
[window setWindowProperty:[NSDictionary dictionaryWithObjectsAndKeys:@"QSExplodeEffect",@"transformFn",@"hide",@"type",[NSNumber numberWithFloat:0.09],@"duration",nil] forKey:kQSWindowExecEffect];
[dSelector setCell:[[BHObjectCell alloc] initTextCell:@"BezelHUD"]];
[aSelector setCell:[[BHObjectCell alloc] initTextCell:@"BezelHUD"]];
[iSelector setCell:[[BHObjectCell alloc] initTextCell:@"BezelHUD"]];
NSArray *theControls=[NSArray arrayWithObjects:dSelector,aSelector,iSelector,nil];
foreach(theControl,theControls){
[theControl setPreferredEdge:NSMinYEdge];
[theControl setResultsPadding:NSMinY([dSelector frame])];
NSCell *theCell=[theControl cell];
// [(QSObjectCell *)theCell setTextColor:[NSColor whiteColor]];
// [(QSObjectCell *)theCell setHighlightColor:[NSColor colorWithCalibratedWhite:0.2 alpha:0.4]];
// [(QSObjectCell *)theCell setAlignment:NSCenterTextAlignment];
// If yes, will show info under the title (eg. path)
[(QSObjectCell *)theCell setShowDetails:NO];
}
[(BHCollectingSearchView*)dSelector setIsLeftSelector:true];
[(BHCollectingSearchView*)iSelector setIsLeftSelector:false];
[dSelector setAutoresizingMask:0];
[aSelector setAutoresizingMask:0];
[iSelector setAutoresizingMask:0];
/* Example bindings. */
/* [[[self window] contentView] bind:@"highlightColor"
toObject:[NSUserDefaultsController sharedUserDefaultsController]
withKeyPath:@"values.interface.glassColor"
options:[NSDictionary dictionaryWithObject:NSUnarchiveFromDataTransformerName
forKey:@"NSValueTransformerName"]];
[[[self window] contentView] bind:@"borderWidth"
toObject:[NSUserDefaultsController sharedUserDefaultsController]
withKeyPath:@"values.interface.borderWidth"
options:nil];*/
// Just a reminder that you can do normal NSWindow-ey things...
// [[self window]setMovableByWindowBackground:NO];
[[[self window] contentView] setNeedsDisplay:true];
}
-(void) editorEnabled:(id)sender {
if (sender == dSelector) {
[(BHSearchView*)aSelector setEditorActivated:true];
[(BHCollectingSearchView*)iSelector editorActivation:1];
} else if (sender == iSelector) {
[(BHSearchView*)aSelector setEditorActivated:true];
[(BHCollectingSearchView*)dSelector editorActivation:3];
}
[commandView setHidden:true];
}
-(void) editorDisabled {
[(BHCollectingSearchView*)dSelector editorActivation:0];
[(BHSearchView*)aSelector setEditorActivated:false];
[(BHCollectingSearchView*)iSelector editorActivation:0];
[commandView setHidden:false];
}
- (NSSize)maxIconSize{
return NSMakeSize(128,128);
}
- (void)showMainWindow:(id)sender{
if ([[self window]isVisible])[[self window]pulse:self];
[super showMainWindow:sender];
}
- (void)hideMainWindow:(id)sender{
[[self window] saveFrameUsingName:@"BezelHUDWindow"];
[super hideMainWindow:sender];
}
/*
* If you want an effect such as an animation
* when the indirect selector shows up,
* the next three methods are for you to subclass.
*/
- (void)showIndirectSelector:(id)sender{
[super showIndirectSelector:sender];
}
#define SEL_SPACE 15
- (void)expandWindow:(id)sender{
if ([dSelector currentEditor] || [iSelector currentEditor]) return;
[super expandWindow:sender];
NSRect newRect = [[self window] frame];
newRect.origin.x -= (550- newRect.size.width)/2;
newRect.size.width = 550;
[[self window] setFrame:newRect display:true animate:true];
if (!([dSelector currentEditor] || [iSelector currentEditor])) {
NSRect selRect = NSMakeRect(20, 32, 160, 160);
[dSelector setFrame:selRect];
selRect.origin.x += 160 + SEL_SPACE;
[aSelector setFrame:selRect];
selRect.origin.x += 160 + SEL_SPACE;
[iSelector setFrame:selRect];
}
NSRect cmdFrame = [commandView frame];
cmdFrame.origin.x = newRect.size.width/2 - cmdFrame.size.width/2;
[commandView setFrame:cmdFrame];
NSTextField* txtTitle = [(BHBackgroundView*)[[self window] contentView] text_title];
NSRect titleRect = [txtTitle frame];
titleRect.origin.x = newRect.size.width/2 - titleRect.size.width/2;
[txtTitle setFrame:titleRect];
[[[self window] contentView] setNeedsDisplay:true];
}
- (void)contractWindow:(id)sender{
[super contractWindow:sender];
NSRect newRect = [[self window] frame];
newRect.origin.x -= ((550-174) - newRect.size.width)/2;
newRect.size.width = (550-174);
[[self window] setFrame:newRect display:true animate:true];
if (!([dSelector currentEditor] || [iSelector currentEditor])) {
NSRect selRect = NSMakeRect(20, 32, 160, 160);
[dSelector setFrame:selRect];
selRect.origin.x += 160 + SEL_SPACE;
[aSelector setFrame:selRect];
selRect.origin.x += 160 + SEL_SPACE;
[iSelector setFrame:selRect];
}
NSRect cmdFrame = [commandView frame];
cmdFrame.origin.x = newRect.size.width/2 - cmdFrame.size.width/2;
[commandView setFrame:cmdFrame];
NSTextField* txtTitle = [(BHBackgroundView*)[[self window] contentView] text_title];
NSRect titleRect = [txtTitle frame];
titleRect.origin.x = newRect.size.width/2 - titleRect.size.width/2;
[txtTitle setFrame:titleRect];
[[[self window] contentView] setNeedsDisplay:true];
}
// When something changes, update the command string
- (void)firstResponderChanged:(NSResponder *)aResponder{
[super firstResponderChanged:aResponder];
[self updateDetailsString];
}
- (void)searchObjectChanged:(NSNotification*)notif{
[super searchObjectChanged:notif];
[self updateDetailsString];
if (([dSelector objectValue]) && ([(QSBasicObject*)[dSelector objectValue] details]))
[commandView setStringValue:[(QSBasicObject*)[dSelector objectValue] details]];
}
// The method to update the command string
// Get rid of it if you're not having a commandView outlet
-(void)updateDetailsString{
return;
NSString *command=[[self currentCommand] description];
[commandView setStringValue:command?command:@""];
}
// Uncomment if you're having a customize button + pref pane
/*- (IBAction)customize:(id)sender{
[[NSClassFromString(@"QSPreferencesController") sharedInstance]showPaneWithIdentifier:@"QSFumoInterfacePrefPane"];
}*/
- (void)actionActivate:(id)sender{
[super actionActivate:sender];
}
- (void)updateViewLocations{
[super updateViewLocations];
}
@end