[Spectrum] Enable switching style at runtime
It is now possible to switch the display style at runtime, while the views are open. Signed-off-by: Christopher Snowhill <kode54@gmail.com>lastfm
parent
f4926cf569
commit
d4b434a68f
|
@ -990,6 +990,9 @@
|
|||
<rect key="frame" x="0.0" y="14" width="64" height="26"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
</customView>
|
||||
<connections>
|
||||
<outlet property="playbackController" destination="705" id="FPc-ek-NRd"/>
|
||||
</connections>
|
||||
</toolbarItem>
|
||||
</allowedToolbarItems>
|
||||
<defaultToolbarItems>
|
||||
|
@ -1246,6 +1249,9 @@
|
|||
<rect key="frame" x="0.0" y="14" width="64" height="26"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
</customView>
|
||||
<connections>
|
||||
<outlet property="playbackController" destination="705" id="GWc-77-WHY"/>
|
||||
</connections>
|
||||
</toolbarItem>
|
||||
</allowedToolbarItems>
|
||||
<defaultToolbarItems>
|
||||
|
|
|
@ -363,7 +363,7 @@
|
|||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<clipView key="contentView" id="gUE-Yu-LLA">
|
||||
<rect key="frame" x="1" y="1" width="488" height="113"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" multipleSelection="NO" autosaveColumns="NO" rowHeight="24" rowSizeStyle="automatic" headerView="9rQ-Rq-K6J" viewBased="YES" id="gHG-xw-OyR">
|
||||
<rect key="frame" x="0.0" y="0.0" width="488" height="85"/>
|
||||
|
@ -385,7 +385,7 @@
|
|||
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
|
||||
<prototypeCellViews>
|
||||
<tableCellView id="EEt-uJ-j6o">
|
||||
<rect key="frame" x="18" y="0.0" width="386" height="24"/>
|
||||
<rect key="frame" x="8" y="0.0" width="386" height="24"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="7l9-R2-FVF">
|
||||
|
@ -420,7 +420,7 @@
|
|||
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
|
||||
<prototypeCellViews>
|
||||
<tableCellView id="EDi-gi-Vg9">
|
||||
<rect key="frame" x="421" y="0.0" width="38" height="24"/>
|
||||
<rect key="frame" x="411" y="0.0" width="38" height="24"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="0TJ-dK-Rfk">
|
||||
|
@ -538,19 +538,19 @@
|
|||
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="4xb-C2-wmz">
|
||||
<rect key="frame" x="40" y="78" width="470" height="18"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
|
||||
<buttonCell key="cell" type="check" title="Spectrum 2D view" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="gXL-j6-df0">
|
||||
<buttonCell key="cell" type="check" title="Use flat perspective in toolbar" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="gXL-j6-df0">
|
||||
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
</buttonCell>
|
||||
<connections>
|
||||
<binding destination="52" name="enabled" keyPath="values.spectrumSceneKit" id="frQ-l7-tCE"/>
|
||||
<binding destination="52" name="value" keyPath="values.spectrumProjectionMode" id="UGh-1j-iFC"/>
|
||||
<binding destination="52" name="enabled" keyPath="values.spectrumSceneKit" id="frQ-l7-tCE"/>
|
||||
</connections>
|
||||
</button>
|
||||
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="t6C-Va-hmO" userLabel="Use SceneKit">
|
||||
<rect key="frame" x="18" y="104" width="108" height="18"/>
|
||||
<rect key="frame" x="18" y="104" width="492" height="18"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
|
||||
<buttonCell key="cell" type="check" title="Use SceneKit" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="NMg-TO-amV">
|
||||
<buttonCell key="cell" type="check" title="Use 3D rendered spectrum" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="NMg-TO-amV">
|
||||
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
</buttonCell>
|
||||
|
|
|
@ -198,7 +198,7 @@
|
|||
"ds2-aw-ebU.title" = "Limit volume control to 100%";
|
||||
|
||||
/* Class = "NSButtonCell"; title = "Spectrum 2D view"; ObjectID = "gXL-j6-df0"; */
|
||||
"gXL-j6-df0.title" = "Spectrum 2D view";
|
||||
"gXL-j6-df0.title" = "Use flat perspective in toolbar";
|
||||
|
||||
/* Class = "NSTextFieldCell"; title = "hh:mm:ss.ms"; ObjectID = "klv-Wh-0ur"; */
|
||||
"klv-Wh-0ur.title" = "hh:mm:ss.ms";
|
||||
|
@ -226,3 +226,7 @@
|
|||
|
||||
/* Class = "NSButtonCell"; title = "Send crash reports and usage data"; ObjectID = "zQ2-6O-3Og"; */
|
||||
"zQ2-6O-3Og.title" = "Send crash reports and usage data";
|
||||
|
||||
/* Class = "NSButtonCell"; title = "Use 3D rendered spectrum"; ObjectID = "NMg-TO-amV"; */
|
||||
"NMg-TO-amV.title" = "Use 3D rendered spectrum";
|
||||
|
||||
|
|
|
@ -109,9 +109,6 @@
|
|||
/* Class = "NSButtonCell"; title = "Colorful dock icons"; ObjectID = "GdX-5e-NeU"; */
|
||||
"GdX-5e-NeU.title" = "Colorear icono del dock";
|
||||
|
||||
/* Class = "NSButtonCell"; title = "Spectrum 2D view"; ObjectID = "gXL-j6-df0"; */
|
||||
"gXL-j6-df0.title" = "Analizador en 2D";
|
||||
|
||||
/* Class = "NSMenu"; title = "OtherViews"; ObjectID = "HKM-FW-dhH"; */
|
||||
"HKM-FW-dhH.title" = "Otras vistas";
|
||||
|
||||
|
@ -240,3 +237,10 @@
|
|||
|
||||
/* Class = "NSTextFieldCell"; title = "hh:mm:ss.ms"; ObjectID = "zaI-0m-tQf"; */
|
||||
"zaI-0m-tQf.title" = "hh:mm:ss.ms";
|
||||
|
||||
/* Class = "NSButtonCell"; title = "Spectrum 2D view"; ObjectID = "gXL-j6-df0"; */
|
||||
"gXL-j6-df0.title" = "Use flat perspective in toolbar";
|
||||
|
||||
/* Class = "NSButtonCell"; title = "Use 3D rendered spectrum"; ObjectID = "NMg-TO-amV"; */
|
||||
"NMg-TO-amV.title" = "Use 3D rendered spectrum";
|
||||
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
#import "SpectrumViewSK.h"
|
||||
#import "SpectrumViewCG.h"
|
||||
|
||||
static void *kSpectrumWindowContext = &kSpectrumWindowContext;
|
||||
|
||||
@interface SpectrumWindowController ()
|
||||
@property SpectrumViewSK *spectrumViewSK;
|
||||
@property SpectrumViewCG *spectrumViewCG;
|
||||
|
@ -18,7 +20,11 @@
|
|||
@implementation SpectrumWindowController
|
||||
|
||||
- (id)init {
|
||||
return [super initWithWindowNibName:@"SpectrumWindow"];
|
||||
self = [super initWithWindowNibName:@"SpectrumWindow"];
|
||||
if(self) {
|
||||
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.spectrumSceneKit" options:0 context:kSpectrumWindowContext];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)windowDidLoad {
|
||||
|
@ -27,6 +33,25 @@
|
|||
[self startRunning];
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.spectrumSceneKit" context:kSpectrumWindowContext];
|
||||
}
|
||||
|
||||
- (void)observeValueForKeyPath:(NSString *)keyPath
|
||||
ofObject:(id)object
|
||||
change:(NSDictionary<NSKeyValueChangeKey, id> *)change
|
||||
context:(void *)context {
|
||||
if(context == kSpectrumWindowContext) {
|
||||
if([keyPath isEqualToString:@"values.spectrumSceneKit"]) {
|
||||
self.spectrumViewSK = nil;
|
||||
self.spectrumViewCG = nil;
|
||||
[self startRunning];
|
||||
}
|
||||
} else {
|
||||
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)startRunning {
|
||||
if(!self.spectrumViewSK && !self.spectrumViewCG) {
|
||||
NSRect frame = [[self window] frame];
|
||||
|
|
|
@ -7,10 +7,13 @@
|
|||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
#import "PlaybackController.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface SpectrumItem : NSToolbarItem
|
||||
|
||||
@interface SpectrumItem : NSToolbarItem {
|
||||
IBOutlet PlaybackController *playbackController;
|
||||
}
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
|
|
@ -12,14 +12,60 @@
|
|||
|
||||
#import "Logging.h"
|
||||
|
||||
static void *kSpectrumItemContext = &kSpectrumItemContext;
|
||||
|
||||
@interface SpectrumItem ()
|
||||
@property SpectrumViewSK *spectrumViewSK;
|
||||
@property SpectrumViewCG *spectrumViewCG;
|
||||
@end
|
||||
|
||||
@implementation SpectrumItem
|
||||
|
||||
- (void)awakeFromNib {
|
||||
NSRect frame = NSMakeRect(0, 0, 64, 26);
|
||||
NSView *view = nil;
|
||||
if(self.toolbar) view = [SpectrumViewSK createGuardWithFrame:frame];
|
||||
if(!view) view = [[SpectrumViewCG alloc] initWithFrame:frame];
|
||||
[self setView:view];
|
||||
[self startRunning];
|
||||
|
||||
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.spectrumSceneKit" options:0 context:kSpectrumItemContext];
|
||||
}
|
||||
|
||||
- (void)startRunning {
|
||||
if(!self.spectrumViewSK && !self.spectrumViewCG) {
|
||||
NSRect frame = NSMakeRect(0, 0, 64, 26);
|
||||
self.spectrumViewSK = [SpectrumViewSK createGuardWithFrame:frame];
|
||||
if(self.spectrumViewSK) {
|
||||
[self setView:self.spectrumViewSK];
|
||||
} else {
|
||||
self.spectrumViewCG = [[SpectrumViewCG alloc] initWithFrame:frame];
|
||||
if(self.spectrumViewCG) {
|
||||
[self setView:self.spectrumViewCG];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(playbackController.playbackStatus == CogStatusPlaying) {
|
||||
if(self.spectrumViewSK)
|
||||
[self.spectrumViewSK startPlayback];
|
||||
else if(self.spectrumViewCG)
|
||||
[self.spectrumViewCG startPlayback];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.spectrumSceneKit" context:kSpectrumItemContext];
|
||||
}
|
||||
|
||||
- (void)observeValueForKeyPath:(NSString *)keyPath
|
||||
ofObject:(id)object
|
||||
change:(NSDictionary<NSKeyValueChangeKey, id> *)change
|
||||
context:(void *)context {
|
||||
if(context == kSpectrumItemContext) {
|
||||
if([keyPath isEqualToString:@"values.spectrumSceneKit"]) {
|
||||
self.spectrumViewSK = nil;
|
||||
self.spectrumViewCG = nil;
|
||||
[self startRunning];
|
||||
}
|
||||
} else {
|
||||
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
Loading…
Reference in New Issue