If you have an issue with any of our projects. feel free to register.

Commit 9b9e2d2c authored by Dmitry Nevedomsky's avatar Dmitry Nevedomsky

Show Volume slider in NSPopover instead of CGWindow.

Also perform Haptic feedback when volume slider is at 100%.
parent c0a349d6
......@@ -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
{
double change = [theEvent deltaY];
[(VolumeSlider *)_popView setDoubleValue:[(VolumeSlider *)_popView doubleValue] + change];
[[(VolumeSlider *)_popView target] changeVolume:_popView];
[(VolumeSlider *)_popView showToolTipForView:self closeAfter:1.0];
if ([popover isShown]) {
[_popView scrollWheel:theEvent];
return;
}
double change = [theEvent deltaY];
[_popView setDoubleValue:[_popView doubleValue] + change];
[[_popView target] changeVolume:_popView];
[_popView showToolTipForView:self closeAfter:1.0];
}
- (void)mouseDown:(NSEvent *)theEvent
{
[(VolumeSlider *)_popView hideToolTip];
[super mouseDown:theEvent];
[_popView hideToolTip];
[popover showRelativeToRect:self.bounds ofView:self preferredEdge:NSRectEdgeMaxY];
[(VolumeSlider *)_popView hideToolTip];
[super mouseDown:theEvent];
}
......
......@@ -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];
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment