Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
C
cog
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Package Registry
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
If you have an issue with any of our projects. feel free to register.
Open sidebar
Christopher Snowhill
cog
Commits
76bdebd0
Commit
76bdebd0
authored
Jan 07, 2021
by
Dmitry Nevedomsky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update volume slider to use NSPopover.
parent
42690a80
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
96 additions
and
55 deletions
+96
-55
Base.lproj/MainMenu.xib
Base.lproj/MainMenu.xib
+5
-5
Window/VolumeButton.m
Window/VolumeButton.m
+1
-1
Window/VolumeSlider.h
Window/VolumeSlider.h
+3
-1
Window/VolumeSlider.m
Window/VolumeSlider.m
+87
-48
No files found.
Base.lproj/MainMenu.xib
View file @
76bdebd0
...
...
@@ -1739,19 +1739,19 @@ Gw
</items>
</menu>
<customView
id=
"1611"
userLabel=
"Volume View"
>
<rect
key=
"frame"
x=
"0.0"
y=
"0.0"
width=
"
26
"
height=
"168"
/>
<autoresizingMask
key=
"autoresizingMask"
/>
<rect
key=
"frame"
x=
"0.0"
y=
"0.0"
width=
"
32
"
height=
"168"
/>
<autoresizingMask
key=
"autoresizingMask"
flexibleMinX=
"YES"
flexibleMaxX=
"YES"
flexibleMinY=
"YES"
flexibleMaxY=
"YES"
/>
<subviews>
<slider
horizontalHuggingPriority=
"750"
fixedFrame=
"YES"
translatesAutoresizingMaskIntoConstraints=
"NO"
id=
"1612"
customClass=
"VolumeSlider"
>
<rect
key=
"frame"
x=
"6"
y=
"
19"
width=
"15"
height=
"129
"
/>
<rect
key=
"frame"
x=
"6"
y=
"
2"
width=
"20"
height=
"164
"
/>
<autoresizingMask
key=
"autoresizingMask"
/>
<sliderCell
key=
"cell"
controlSize=
"small"
continuous=
"YES"
alignment=
"left"
m
axValue=
"100"
doubleValue=
"50
"
tickMarkPosition=
"left"
sliderType=
"linear"
id=
"1613"
/>
<sliderCell
key=
"cell"
controlSize=
"small"
continuous=
"YES"
alignment=
"left"
m
inValue=
"10"
maxValue=
"100"
doubleValue=
"55
"
tickMarkPosition=
"left"
sliderType=
"linear"
id=
"1613"
/>
<connections>
<action
selector=
"changeVolume:"
target=
"705"
id=
"1614"
/>
</connections>
</slider>
</subviews>
<point
key=
"canvasLocation"
x=
"
-137"
y=
"118
"
/>
<point
key=
"canvasLocation"
x=
"
615"
y=
"-25
"
/>
</customView>
<customObject
id=
"1675"
customClass=
"SpotlightWindowController"
>
<connections>
...
...
Window/VolumeButton.m
View file @
76bdebd0
...
...
@@ -20,7 +20,7 @@
[[(
VolumeSlider
*
)
_popView
target
]
changeVolume
:
_popView
];
[(
VolumeSlider
*
)
_popView
showToolTipFor
Duration
:
1
.
0
];
[(
VolumeSlider
*
)
_popView
showToolTipFor
View
:
self
closeAfter
:
1
.
0
];
}
-
(
void
)
mouseDown
:(
NSEvent
*
)
theEvent
...
...
Window/VolumeSlider.h
View file @
76bdebd0
...
...
@@ -10,11 +10,13 @@
#import "ToolTipWindow.h"
@interface
VolumeSlider
:
NSSlider
{
ToolTipWindow
*
toolTip
;
NSPopover
*
popover
;
NSText
*
textView
;
}
-
(
void
)
showToolTip
;
-
(
void
)
showToolTipForDuration
:(
NSTimeInterval
)
duration
;
-
(
void
)
showToolTipForView
:(
NSView
*
)
view
closeAfter
:(
NSTimeInterval
)
duration
;
-
(
void
)
hideToolTip
;
@end
Window/VolumeSlider.m
View file @
76bdebd0
...
...
@@ -10,87 +10,126 @@
#import "PlaybackController.h"
#import "CogAudio/Helper.h"
@implementation
VolumeSlider
@implementation
VolumeSlider
{
NSTimer
*
currentTimer
;
}
-
(
id
)
initWithFrame
:(
NSRect
)
frame
{
self
=
[
super
initWithFrame
:
frame
];
if
(
self
)
{
toolTip
=
[[
ToolTipWindow
alloc
]
init
];
}
return
self
;
self
=
[
super
initWithFrame
:
frame
];
return
self
;
}
-
(
id
)
initWithCoder
:(
NSCoder
*
)
coder
{
self
=
[
super
initWithCoder
:
coder
];
if
(
self
)
{
toolTip
=
[[
ToolTipWindow
alloc
]
init
];
}
return
self
;
self
=
[
super
initWithCoder
:
coder
];
return
self
;
}
-
(
void
)
awakeFromNib
{
textView
=
[[
NSText
alloc
]
init
];
[
textView
setFrame
:
NSMakeRect
(
0
,
0
,
50
,
20
)];
textView
.
drawsBackground
=
NO
;
textView
.
editable
=
NO
;
textView
.
alignment
=
NSTextAlignmentCenter
;
NSViewController
*
viewController
=
[[
NSViewController
alloc
]
init
];
viewController
.
view
=
textView
;
popover
=
[[
NSPopover
alloc
]
init
];
popover
.
contentViewController
=
viewController
;
// Don't hide the popover automatically.
popover
.
behavior
=
NSPopoverBehaviorApplicationDefined
;
popover
.
animates
=
NO
;
[
popover
setContentSize
:
textView
.
bounds
.
size
];
}
-
(
void
)
updateToolTip
{
double
value
=
[
self
doubleValue
];
double
volume
=
linearToLogarithmic
(
value
);
NSString
*
text
=
[[
NSString
alloc
]
initWithFormat
:
@"%0.lf%%"
,
volume
];
NSSize
size
=
[
toolTip
suggestedSizeForTooltip
:
text
];
NSPoint
mouseLocation
=
[
NSEvent
mouseLocation
];
[
toolTip
setToolTip
:
text
];
[
toolTip
setFrame
:
NSMakeRect
(
mouseLocation
.
x
,
mouseLocation
.
y
,
size
.
width
,
size
.
height
)
display
:
YES
];
double
value
=
[
self
doubleValue
];
double
volume
=
linearToLogarithmic
(
value
);
NSString
*
text
=
[
NSString
stringWithFormat
:
@"%0.lf%%"
,
volume
];
[
textView
setString
:
text
];
}
-
(
void
)
showToolTip
{
[
self
updateToolTip
];
[
toolTip
orderFront
];
[
self
updateToolTip
];
double
progress
=
(
self
.
maxValue
-
[
self
doubleValue
])
/
(
self
.
maxValue
-
self
.
minValue
);
CGFloat
width
=
self
.
knobThickness
-
1
;
// Show tooltip to the left of the Slider Knob
CGFloat
height
=
self
.
knobThickness
/
2
.
f
+
(
self
.
bounds
.
size
.
height
-
self
.
knobThickness
)
*
progress
-
1
;
[
popover
showRelativeToRect
:
NSMakeRect
(
width
,
height
,
2
,
2
)
ofView
:
self
preferredEdge
:
NSRectEdgeMaxX
];
[
self
.
window
.
parentWindow
makeKeyWindow
];
}
-
(
void
)
showToolTipForDuration
:(
NSTimeInterval
)
duration
{
[
self
updateToolTip
];
[
toolTip
orderFrontForDuration
:
duration
];
[
self
showToolTip
];
[
self
hideToolTipAfterDelay
:
duration
];
}
-
(
void
)
showToolTipForView
:(
NSView
*
)
view
closeAfter
:(
NSTimeInterval
)
duration
{
[
self
updateToolTip
];
[
popover
showRelativeToRect
:
view
.
bounds
ofView
:
view
preferredEdge
:
NSRectEdgeMaxY
];
[
self
hideToolTipAfterDelay
:
duration
];
}
-
(
void
)
hideToolTip
{
[
toolTip
close
];
[
popover
close
];
}
-
(
void
)
hideToolTipAfterDelay
:(
NSTimeInterval
)
duration
{
if
(
currentTimer
)
{
[
currentTimer
invalidate
];
currentTimer
=
nil
;
}
if
(
duration
>
0
.
0
)
{
currentTimer
=
[
NSTimer
scheduledTimerWithTimeInterval
:
duration
target:
self
selector:
@selector
(
hideToolTip
)
userInfo:
nil
repeats:
NO
];
[[
NSRunLoop
mainRunLoop
]
addTimer
:
currentTimer
forMode
:
NSRunLoopCommonModes
];
}
}
-
(
BOOL
)
sendAction
:(
SEL
)
theAction
to
:(
id
)
theTarget
{
double
oneLog
=
logarithmicToLinear
(
100
.
0
);
double
distance
=
[
self
frame
].
size
.
height
*
([
self
doubleValue
]
-
oneLog
)
/
100
.
0
;
if
(
fabs
(
distance
)
<
2
.
0
)
{
[
self
setDoubleValue
:
oneLog
];
}
[
self
showToolTip
];
return
[
super
sendAction
:
theAction
to
:
theTarget
];
// 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
];
}
[
self
showToolTip
];
return
[
super
sendAction
:
theAction
to
:
theTarget
];
}
-
(
void
)
scrollWheel
:(
NSEvent
*
)
theEvent
{
double
change
=
[
theEvent
deltaY
];
[
self
setDoubleValue
:[
self
doubleValue
]
+
change
];
[[
self
target
]
changeVolume
:
self
];
[
self
showToolTipForDuration
:
1
.
0
];
double
change
=
[
theEvent
deltaY
];
[
self
setDoubleValue
:[
self
doubleValue
]
+
change
];
[[
self
target
]
changeVolume
:
self
];
[
self
showToolTipForDuration
:
1
.
0
];
}
@end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment