Merge pull request #69 from nevack/nevack/volume-slider-popover
Show Volume slider in NSPopover instead of CGWindow.CQTexperiment
commit
0fdabd55dd
|
@ -6,9 +6,11 @@
|
|||
// Copyright 2009 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
#import "PopupButton.h"
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import "VolumeSlider.h"
|
||||
|
||||
@interface VolumeButton : PopupButton {
|
||||
@interface VolumeButton : NSButton {
|
||||
IBOutlet VolumeSlider *_popView;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -7,29 +7,45 @@
|
|||
//
|
||||
|
||||
#import "VolumeButton.h"
|
||||
#import "VolumeSlider.h"
|
||||
#import "PlaybackController.h"
|
||||
|
||||
@implementation VolumeButton
|
||||
@implementation VolumeButton {
|
||||
NSPopover *popover;
|
||||
}
|
||||
|
||||
- (void)awakeFromNib
|
||||
{
|
||||
popover = [[NSPopover alloc] init];
|
||||
|
||||
NSViewController * viewController = [[NSViewController alloc] init];
|
||||
viewController.view = _popView;
|
||||
popover.contentViewController = viewController;
|
||||
popover.behavior = NSPopoverBehaviorTransient;
|
||||
[popover setContentSize:_popView.bounds.size];
|
||||
}
|
||||
|
||||
- (void)scrollWheel:(NSEvent *)theEvent
|
||||
{
|
||||
if ([popover isShown]) {
|
||||
[_popView scrollWheel:theEvent];
|
||||
return;
|
||||
}
|
||||
|
||||
double change = [theEvent deltaY];
|
||||
|
||||
[(VolumeSlider *)_popView setDoubleValue:[(VolumeSlider *)_popView doubleValue] + change];
|
||||
[_popView setDoubleValue:[_popView doubleValue] + change];
|
||||
|
||||
[[(VolumeSlider *)_popView target] changeVolume:_popView];
|
||||
[[_popView target] changeVolume:_popView];
|
||||
|
||||
[(VolumeSlider *)_popView showToolTipForView:self closeAfter:1.0];
|
||||
[_popView showToolTipForView:self closeAfter:1.0];
|
||||
}
|
||||
|
||||
- (void)mouseDown:(NSEvent *)theEvent
|
||||
{
|
||||
[(VolumeSlider *)_popView hideToolTip];
|
||||
[_popView hideToolTip];
|
||||
[popover showRelativeToRect:self.bounds ofView:self preferredEdge:NSRectEdgeMaxY];
|
||||
|
||||
[super mouseDown:theEvent];
|
||||
|
||||
[(VolumeSlider *)_popView hideToolTip];
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
|
||||
@implementation VolumeSlider {
|
||||
NSTimer *currentTimer;
|
||||
BOOL wasInsideSnapRange;
|
||||
}
|
||||
|
||||
- (id)initWithFrame:(NSRect)frame
|
||||
|
@ -27,6 +28,7 @@
|
|||
}
|
||||
|
||||
- (void) awakeFromNib {
|
||||
wasInsideSnapRange = NO;
|
||||
textView = [[NSText alloc] init];
|
||||
[textView setFrame:NSMakeRect(0, 0, 50, 20)];
|
||||
textView.drawsBackground = NO;
|
||||
|
@ -39,7 +41,7 @@
|
|||
popover = [[NSPopover alloc] init];
|
||||
popover.contentViewController = viewController;
|
||||
// Don't hide the popover automatically.
|
||||
popover.behavior = NSPopoverBehaviorApplicationDefined;
|
||||
popover.behavior = NSPopoverBehaviorTransient;
|
||||
popover.animates = NO;
|
||||
[popover setContentSize:textView.bounds.size];
|
||||
}
|
||||
|
@ -111,9 +113,23 @@
|
|||
// Snap to 100% if value is close
|
||||
double snapTarget = logarithmicToLinear(100.0);
|
||||
double snapProgress = ([self doubleValue] - snapTarget) / (self.maxValue - self.minValue);
|
||||
|
||||
if (fabs(snapProgress) < 0.005)
|
||||
{
|
||||
[self setDoubleValue:snapTarget];
|
||||
if (!wasInsideSnapRange)
|
||||
{
|
||||
if (@available(macOS 10.11, *))
|
||||
{
|
||||
[[NSHapticFeedbackManager defaultPerformer] performFeedbackPattern:NSHapticFeedbackPatternGeneric
|
||||
performanceTime:NSHapticFeedbackPerformanceTimeDefault];
|
||||
}
|
||||
}
|
||||
wasInsideSnapRange = YES;
|
||||
}
|
||||
else
|
||||
{
|
||||
wasInsideSnapRange = NO;
|
||||
}
|
||||
|
||||
[self showToolTip];
|
||||
|
|
Loading…
Reference in New Issue