From c9e542f5708bc0c8ed64eabbdf39fe90a8e26676 Mon Sep 17 00:00:00 2001 From: vspader Date: Mon, 9 Feb 2009 05:53:38 +0000 Subject: [PATCH] Added better tooltip feedback. --- Application/PlaybackController.m | 7 -- Audio/Helper.h | 2 +- Audio/Helper.m | 2 +- Cog.xcodeproj/project.pbxproj | 26 +++++ English.lproj/MainMenu.xib | 132 ++++++++++++++++--------- ThirdParty/GCWindowMenu/GCWindowMenu.m | 4 +- ThirdParty/GCWindowMenu/PopupButton.m | 1 - ThirdParty/ToolTip/ToolTipWindow.h | 38 +++++++ ThirdParty/ToolTip/ToolTipWindow.m | 123 +++++++++++++++++++++++ Utils/VolumeButton.h | 14 +++ Utils/VolumeButton.m | 29 ++++++ Utils/VolumeSlider.h | 20 ++++ Utils/VolumeSlider.m | 87 ++++++++++++++++ 13 files changed, 428 insertions(+), 57 deletions(-) create mode 100644 ThirdParty/ToolTip/ToolTipWindow.h create mode 100644 ThirdParty/ToolTip/ToolTipWindow.m create mode 100644 Utils/VolumeButton.h create mode 100644 Utils/VolumeButton.m create mode 100644 Utils/VolumeSlider.h create mode 100644 Utils/VolumeSlider.m diff --git a/Application/PlaybackController.m b/Application/PlaybackController.m index f41a5a2f8..ddad96d99 100644 --- a/Application/PlaybackController.m +++ b/Application/PlaybackController.m @@ -259,13 +259,6 @@ - (IBAction)changeVolume:(id)sender { - double oneLog = logarithmicToLinear(100.0); - double distance = [sender frame].size.height*([sender doubleValue] - oneLog)/100.0; - if (fabs(distance) < 2.0) - { - [sender setDoubleValue:oneLog]; - } - NSLog(@"VOLUME: %lf, %lf", [sender doubleValue], linearToLogarithmic([sender doubleValue])); [audioPlayer setVolume:linearToLogarithmic([sender doubleValue])]; diff --git a/Audio/Helper.h b/Audio/Helper.h index 624bc99bd..90bc92593 100644 --- a/Audio/Helper.h +++ b/Audio/Helper.h @@ -7,7 +7,7 @@ * */ -#define MAX_VOLUME 400 +#define MAX_VOLUME 400.0 double logarithmicToLinear(double logarithmic); double linearToLogarithmic(double linear); diff --git a/Audio/Helper.m b/Audio/Helper.m index 7ed20c08b..4c885ce0b 100644 --- a/Audio/Helper.m +++ b/Audio/Helper.m @@ -22,6 +22,6 @@ double logarithmicToLinear(double logarithmic) double linearToLogarithmic(double linear) { - return (linear/100) * (linear/100) * (linear/100) * (linear/100) * MAX_VOLUME; + return (linear/100.0) * (linear/100.0) * (linear/100.0) * (linear/100.0) * MAX_VOLUME; } //End helper volume function thingies. ONWARDS TO GLORY! diff --git a/Cog.xcodeproj/project.pbxproj b/Cog.xcodeproj/project.pbxproj index d1f8bb2d0..1dce1bca6 100644 --- a/Cog.xcodeproj/project.pbxproj +++ b/Cog.xcodeproj/project.pbxproj @@ -24,6 +24,9 @@ 173855FF0E0CC81F00488CD4 /* FileTreeOutlineView.m in Sources */ = {isa = PBXBuildFile; fileRef = 173855FE0E0CC81F00488CD4 /* FileTreeOutlineView.m */; }; 1738589B0E0D92DD00488CD4 /* SideBarController.m in Sources */ = {isa = PBXBuildFile; fileRef = 173858950E0D92DD00488CD4 /* SideBarController.m */; }; 1738589D0E0D92DD00488CD4 /* SideWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 173858990E0D92DD00488CD4 /* SideWindowController.m */; }; + 173A43A10F3FD26500676A7B /* ToolTipWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 173A43A00F3FD26500676A7B /* ToolTipWindow.m */; }; + 173A43B80F3FD3B200676A7B /* VolumeButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 173A43B70F3FD3B200676A7B /* VolumeButton.m */; }; + 1752C6B00F3FE3CC00FC3235 /* VolumeSlider.m in Sources */ = {isa = PBXBuildFile; fileRef = 1752C6AF0F3FE3CC00FC3235 /* VolumeSlider.m */; }; 1755E1F90BA0D2B600CA3560 /* PlaylistLoader.m in Sources */ = {isa = PBXBuildFile; fileRef = 1755E1F70BA0D2B600CA3560 /* PlaylistLoader.m */; }; 1766C6930B911DF1004A7AE4 /* AudioScrobbler.m in Sources */ = {isa = PBXBuildFile; fileRef = 1766C68F0B911DF1004A7AE4 /* AudioScrobbler.m */; }; 1766C6950B911DF1004A7AE4 /* AudioScrobblerClient.m in Sources */ = {isa = PBXBuildFile; fileRef = 1766C6910B911DF1004A7AE4 /* AudioScrobblerClient.m */; }; @@ -524,6 +527,12 @@ 173858950E0D92DD00488CD4 /* SideBarController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SideBarController.m; path = SideView/SideBarController.m; sourceTree = ""; }; 173858980E0D92DD00488CD4 /* SideWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SideWindowController.h; path = SideView/SideWindowController.h; sourceTree = ""; }; 173858990E0D92DD00488CD4 /* SideWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SideWindowController.m; path = SideView/SideWindowController.m; sourceTree = ""; }; + 173A439F0F3FD26500676A7B /* ToolTipWindow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ToolTipWindow.h; path = ToolTip/ToolTipWindow.h; sourceTree = ""; }; + 173A43A00F3FD26500676A7B /* ToolTipWindow.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ToolTipWindow.m; path = ToolTip/ToolTipWindow.m; sourceTree = ""; }; + 173A43B60F3FD3B200676A7B /* VolumeButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VolumeButton.h; sourceTree = ""; }; + 173A43B70F3FD3B200676A7B /* VolumeButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VolumeButton.m; sourceTree = ""; }; + 1752C6AE0F3FE3CC00FC3235 /* VolumeSlider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VolumeSlider.h; sourceTree = ""; }; + 1752C6AF0F3FE3CC00FC3235 /* VolumeSlider.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VolumeSlider.m; sourceTree = ""; }; 1755E1F60BA0D2B600CA3560 /* PlaylistLoader.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = PlaylistLoader.h; sourceTree = ""; }; 1755E1F70BA0D2B600CA3560 /* PlaylistLoader.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = PlaylistLoader.m; sourceTree = ""; }; 1766C68E0B911DF1004A7AE4 /* AudioScrobbler.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = AudioScrobbler.h; sourceTree = ""; }; @@ -790,6 +799,15 @@ name = "Other Frameworks"; sourceTree = ""; }; + 173A439D0F3FD25500676A7B /* ToolTip */ = { + isa = PBXGroup; + children = ( + 173A439F0F3FD26500676A7B /* ToolTipWindow.h */, + 173A43A00F3FD26500676A7B /* ToolTipWindow.m */, + ); + name = ToolTip; + sourceTree = ""; + }; 1766C68D0B911DF1004A7AE4 /* AudioScrobbler */ = { isa = PBXGroup; children = ( @@ -819,6 +837,7 @@ 177EBF770B8BC2A70000BC8C /* ThirdParty */ = { isa = PBXGroup; children = ( + 173A439D0F3FD25500676A7B /* ToolTip */, 178BAB920CD4E1B700B33D47 /* GCWindowMenu */, 177EBF7D0B8BC2A70000BC8C /* AppleRemote */, 177EBF850B8BC2A70000BC8C /* ImageTextCell */, @@ -878,6 +897,10 @@ 17E78CB00D68D46F005C5A59 /* StringToURLTransformer.m */, 56AE86BF0D6901BC00B0F89B /* FontSizetoLineHeightTransformer.h */, 56AE86C00D6901BC00B0F89B /* FontSizetoLineHeightTransformer.m */, + 173A43B60F3FD3B200676A7B /* VolumeButton.h */, + 173A43B70F3FD3B200676A7B /* VolumeButton.m */, + 1752C6AE0F3FE3CC00FC3235 /* VolumeSlider.h */, + 1752C6AF0F3FE3CC00FC3235 /* VolumeSlider.m */, ); path = Utils; sourceTree = ""; @@ -1794,6 +1817,9 @@ 1738589B0E0D92DD00488CD4 /* SideBarController.m in Sources */, 1738589D0E0D92DD00488CD4 /* SideWindowController.m in Sources */, 07D971E60ED1DAA800E7602E /* TagEditorController.m in Sources */, + 173A43A10F3FD26500676A7B /* ToolTipWindow.m in Sources */, + 173A43B80F3FD3B200676A7B /* VolumeButton.m in Sources */, + 1752C6B00F3FE3CC00FC3235 /* VolumeSlider.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/English.lproj/MainMenu.xib b/English.lproj/MainMenu.xib index 6d1a56f11..4dc7d8d99 100644 --- a/English.lproj/MainMenu.xib +++ b/English.lproj/MainMenu.xib @@ -1,26 +1,36 @@ - + 1050 - 9F33 - 667 - 949.34 - 352.00 + 9G55 + 677 + 949.43 + 353.00 YES - + + + + - + - - YES com.apple.InterfaceBuilder.CocoaPlugin + + YES + + YES + + + YES + + YES @@ -78,9 +88,10 @@ Search - + 268 {{0, 14}, {96, 22}} + YES 343014976 @@ -177,9 +188,10 @@ Position - + 270 {{0, 14}, {96, 15}} + YES 604372736 @@ -205,7 +217,7 @@ {96, 15} - {10000, 15} + {96, 15} NO YES 0 @@ -220,9 +232,10 @@ Info Drawer - + 268 {{23, 14}, {24, 25}} + YES 67239424 @@ -261,9 +274,10 @@ Shuffle - + 268 {{10, 14}, {24, 25}} + YES 67239424 @@ -302,9 +316,10 @@ Volume - + 268 {{12, 14}, {24, 25}} + YES 67239424 @@ -343,9 +358,10 @@ File Tree - + 268 - {{14, 14}, {24, 25}} + {{15, 14}, {24, 25}} + YES 67239424 @@ -384,9 +400,10 @@ Playback Buttons - + 268 {{9, 14}, {80, 24}} + YES -2080244224 @@ -450,9 +467,10 @@ Current Time - + 268 {{20, 14}, {38, 14}} + YES 67239488 @@ -491,9 +509,10 @@ Repeat - + 268 {{10, 14}, {24, 25}} + YES 67239424 @@ -3316,7 +3335,7 @@ OQA FileTreeDataSource - + 256 YES @@ -3344,6 +3363,7 @@ OQA {97, 177} + NSView @@ -4698,14 +4718,6 @@ OQA 1615 - - - _popView - - - - 1616 - value: arrangedObjects.length @@ -6243,6 +6255,14 @@ OQA 2219 + + + _popView + + + + 2220 + @@ -7614,7 +7634,7 @@ OQA - Popup View + Volume View 1612 @@ -8538,10 +8558,10 @@ OQA 1518.ImportedFromIB2 1519.IBPluginDependency 1519.ImportedFromIB2 + 1523.IBEditorWindowLastContentRect 1523.IBPluginDependency 1523.ImportedFromIB2 1523.editorWindowContentRectSynchronizationRect - 1529.IBPluginDependency 1529.ImportedFromIB2 1531.IBPluginDependency 1531.ImportedFromIB2 @@ -8563,7 +8583,6 @@ OQA 1550.ImportedFromIB2 1551.IBPluginDependency 1551.ImportedFromIB2 - 1552.IBPluginDependency 1552.ImportedFromIB2 156.IBPluginDependency 156.ImportedFromIB2 @@ -8587,9 +8606,11 @@ OQA 1609.ImportedFromIB2 1610.IBPluginDependency 1610.ImportedFromIB2 + 1611.IBEditorWindowLastContentRect 1611.IBPluginDependency 1611.ImportedFromIB2 1611.editorWindowContentRectSynchronizationRect + 1612.CustomClassName 1612.IBPluginDependency 1612.ImportedFromIB2 1613.IBPluginDependency @@ -8626,11 +8647,11 @@ OQA 1642.ImportedFromIB2 1645.IBPluginDependency 1645.ImportedFromIB2 - 1673.IBPluginDependency 1675.IBPluginDependency 1683.IBPluginDependency 1685.IBPluginDependency 1688.IBPluginDependency + 1689.IBPluginDependency 169.IBEditorWindowLastContentRect 169.IBPluginDependency 169.ImportedFromIB2 @@ -8639,10 +8660,14 @@ OQA 1701.IBPluginDependency 171.IBPluginDependency 171.ImportedFromIB2 + 1712.IBPluginDependency + 1713.IBPluginDependency 172.IBPluginDependency 172.ImportedFromIB2 173.IBPluginDependency 173.ImportedFromIB2 + 1736.IBPluginDependency + 1737.IBPluginDependency 1740.IBPluginDependency 1741.IBPluginDependency 1741.editorWindowContentRectSynchronizationRect @@ -8651,6 +8676,7 @@ OQA 1748.IBPluginDependency 1749.IBPluginDependency 1791.IBPluginDependency + 1798.IBPluginDependency 1801.IBPluginDependency 1823.IBPluginDependency 1823.ImportedFromIB2 @@ -8710,13 +8736,13 @@ OQA 209.IBPluginDependency 209.ImportedFromIB2 21.IBEditorWindowLastContentRect - 21.IBPluginDependency 21.IBWindowTemplateEditedContentRect 21.ImportedFromIB2 21.NSWindowTemplate.visibleAtLaunch 21.editorWindowContentRectSynchronizationRect 21.windowTemplate.hasMaxSize 21.windowTemplate.maxSize + 2123.IBPluginDependency 2155.IBPluginDependency 2156.IBPluginDependency 2157.IBEditorWindowLastContentRect @@ -8733,7 +8759,6 @@ OQA 218.IBPluginDependency 218.ImportedFromIB2 2187.IBEditorWindowLastContentRect - 2187.IBPluginDependency 2187.IBWindowTemplateEditedContentRect 2187.NSWindowTemplate.visibleAtLaunch 2188.IBPluginDependency @@ -8768,7 +8793,6 @@ OQA 24.ImportedFromIB2 24.editorWindowContentRectSynchronizationRect 268.IBEditorWindowLastContentRect - 268.IBPluginDependency 268.IBWindowTemplateEditedContentRect 268.ImportedFromIB2 268.editorWindowContentRectSynchronizationRect @@ -8794,7 +8818,6 @@ OQA 276.ImportedFromIB2 277.IBPluginDependency 277.ImportedFromIB2 - 280.IBPluginDependency 280.ImportedFromIB2 280.windowTemplate.hasMaxSize 280.windowTemplate.hasMinSize @@ -9105,10 +9128,10 @@ OQA com.apple.InterfaceBuilder.CocoaPlugin + {{140, 396}, {617, 227}} com.apple.InterfaceBuilder.CocoaPlugin {{85, 558}, {617, 0}} - com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -9130,7 +9153,6 @@ OQA com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -9147,16 +9169,18 @@ OQA com.apple.InterfaceBuilder.CocoaPlugin - PopupButton + VolumeButton com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + {{0, 818}, {97, 177}} com.apple.InterfaceBuilder.CocoaPlugin {{37, 809}, {97, 177}} + VolumeSlider com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -9207,11 +9231,15 @@ OQA com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin {{675, 786}, {186, 93}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -9220,6 +9248,7 @@ OQA com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -9277,7 +9306,6 @@ OQA com.apple.InterfaceBuilder.CocoaPlugin {{103, 226}, {691, 397}} - com.apple.InterfaceBuilder.CocoaPlugin {{103, 226}, {691, 397}} @@ -9286,6 +9314,7 @@ OQA {3.40282e+38, 3.40282e+38} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin {{603, 670}, {64, 6}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -9300,7 +9329,6 @@ OQA com.apple.InterfaceBuilder.CocoaPlugin {{92, 297}, {480, 270}} - com.apple.InterfaceBuilder.CocoaPlugin {{92, 297}, {480, 270}} com.apple.InterfaceBuilder.CocoaPlugin @@ -9335,7 +9363,6 @@ OQA {{442, 733}, {197, 103}} {{314, 416}, {480, 376}} - com.apple.InterfaceBuilder.CocoaPlugin {{314, 416}, {480, 376}} {{139, 290}, {480, 376}} @@ -9361,7 +9388,6 @@ OQA com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin @@ -9521,7 +9547,7 @@ OQA - 2219 + 2220 @@ -10235,6 +10261,22 @@ OQA + + VolumeButton + PopupButton + + IBProjectSource + Utils/VolumeButton.h + + + + VolumeSlider + NSSlider + + IBProjectSource + Utils/VolumeSlider.h + + 0 diff --git a/ThirdParty/GCWindowMenu/GCWindowMenu.m b/ThirdParty/GCWindowMenu/GCWindowMenu.m index de1ebecac..8f9831bbc 100644 --- a/ThirdParty/GCWindowMenu/GCWindowMenu.m +++ b/ThirdParty/GCWindowMenu/GCWindowMenu.m @@ -258,7 +258,7 @@ NSLog(@"starting tracking; initial event = %@", event); - //[NSEvent startPeriodicEventsAfterDelay:1.0 withPeriod:0.1]; + // [NSEvent startPeriodicEventsAfterDelay:1.0 withPeriod:0.1]; NSTimeInterval startTime = [event timestamp]; @@ -292,7 +292,7 @@ switch ([theEvent type]) { - case NSMouseMovedMask: + case NSMouseMoved: [[self mainView] mouseMoved:theEvent]; break; diff --git a/ThirdParty/GCWindowMenu/PopupButton.m b/ThirdParty/GCWindowMenu/PopupButton.m index 7fdd76092..3a0ae73a7 100644 --- a/ThirdParty/GCWindowMenu/PopupButton.m +++ b/ThirdParty/GCWindowMenu/PopupButton.m @@ -35,5 +35,4 @@ [self highlight:NO]; } - @end diff --git a/ThirdParty/ToolTip/ToolTipWindow.h b/ThirdParty/ToolTip/ToolTipWindow.h new file mode 100644 index 000000000..f510d07ea --- /dev/null +++ b/ThirdParty/ToolTip/ToolTipWindow.h @@ -0,0 +1,38 @@ +// +// ToolTip.h +// Cog +// +// Created by Vincent Spader on 2/8/09. +// Copyright 2009 __MyCompanyName__. All rights reserved. +// + +// From http://www.cocoadev.com/index.pl?ToolTip + +#import + +@interface ToolTipWindow : NSWindow +{ + id closeTimer; + id tooltipObject; + + NSColor *backgroundColor; + NSDictionary *textAttributes; +} + +// returns the approximate window size needed to display the tooltip string. +- (NSSize)suggestedSizeForTooltip:(id)tooltip; + +// setting and getting the bgColor +- (void)setBackgroundColor:(NSColor *)bgColor; +- (NSColor *)backgroundColor; + +- (id)init; + +- (id)toolTip; +- (void)setToolTip:(id)tip; + +- (void)orderFront; +- (void)orderFrontForDuration:(NSTimeInterval)duration; + +@end + diff --git a/ThirdParty/ToolTip/ToolTipWindow.m b/ThirdParty/ToolTip/ToolTipWindow.m new file mode 100644 index 000000000..25fd7548c --- /dev/null +++ b/ThirdParty/ToolTip/ToolTipWindow.m @@ -0,0 +1,123 @@ +#import "ToolTipWindow.h" + +@implementation ToolTipWindow + +- (void)setBackgroundColor:(NSColor *)bgColor +{ + [backgroundColor release]; + backgroundColor = [bgColor retain]; +} +- (NSColor *)backgroundColor +{ + return backgroundColor; +} + +- (NSSize)suggestedSizeForTooltip:(id)tooltip +{ + NSSize tipSize = NSZeroSize; + + if ([tooltip isKindOfClass:[NSAttributedString class]]) { + tipSize = [tooltip size]; + } + else if ([tooltip isKindOfClass:[NSString class]]){ + tipSize = [tooltip sizeWithAttributes:textAttributes]; + } + + if (!NSEqualSizes(tipSize, NSZeroSize)) + tipSize.width += 4; + + return tipSize; + +} + + +- (id)init +{ + self = [super initWithContentRect:NSMakeRect(0,0,0,0) + styleMask:NSBorderlessWindowMask + backing:NSBackingStoreBuffered + defer:NO]; + + { // window setup... + [self setAlphaValue:0.90]; + [self setOpaque:NO]; + [self setHasShadow:YES]; + [self setBackgroundColor:[NSColor colorWithDeviceRed:1.0 green:0.96 blue:0.76 alpha:1.0]]; + [self setLevel:NSStatusWindowLevel]; + [self setHidesOnDeactivate:YES]; + [self setIgnoresMouseEvents:YES]; + [self setReleasedWhenClosed:NO]; + } + + { // textfield setup... + NSTextField *field = [[NSTextField alloc] initWithFrame:NSMakeRect(0,0,0,0)]; + + [field setEditable:NO]; + [field setSelectable:NO]; + [field setBezeled:NO]; + [field setBordered:NO]; + [field setDrawsBackground:NO]; + [field setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; + [self setContentView:field]; + [self setFrame:[self frameRectForContentRect:[field frame]] display:NO]; + + [field setStringValue:@" "]; // Just having at least 1 char to allow the next message... + textAttributes = [[[field attributedStringValue] attributesAtIndex:0 effectiveRange:nil] retain]; + + [field release]; + } + + return self; +} + + +- (void)dealloc +{ + if (closeTimer) { + [closeTimer invalidate]; + [closeTimer release]; + } + [tooltipObject release]; + [super dealloc]; +} + +- (id)toolTip { return tooltipObject; } + +- (void)setToolTip:(id)tip +{ + id contentView = [self contentView]; + + [tooltipObject release]; + tooltipObject = [tip retain]; + + if ([contentView isKindOfClass:[NSTextField class]]) { + if ([tip isKindOfClass:[NSString class]]) [contentView setStringValue:tip]; + else + if ([tip isKindOfClass:[NSAttributedString class]]) [contentView setAttributedStringValue:tip]; + } +} + +- (void)orderFrontForDuration:(NSTimeInterval)duration +{ + [self orderFront:nil]; + + if (closeTimer) { [closeTimer invalidate]; [closeTimer release]; } + + closeTimer = [[NSTimer scheduledTimerWithTimeInterval:duration target:self selector:@selector(close) userInfo:nil repeats:NO] retain]; +} + +- (void)orderFront +{ + if (closeTimer) { [closeTimer invalidate]; [closeTimer release]; closeTimer = nil; } + + [super orderFront:nil]; +} + + +- (NSString *)description +{ + return [NSString stringWithFormat:@"TooltipWindow:\n%@", [[self contentView] stringValue]]; +} + + +@end \ No newline at end of file diff --git a/Utils/VolumeButton.h b/Utils/VolumeButton.h new file mode 100644 index 000000000..d4354fc95 --- /dev/null +++ b/Utils/VolumeButton.h @@ -0,0 +1,14 @@ +// +// VolumeButton.h +// Cog +// +// Created by Vincent Spader on 2/8/09. +// Copyright 2009 __MyCompanyName__. All rights reserved. +// + +#import "PopupButton.h" + +@interface VolumeButton : PopupButton { +} + +@end diff --git a/Utils/VolumeButton.m b/Utils/VolumeButton.m new file mode 100644 index 000000000..459994f04 --- /dev/null +++ b/Utils/VolumeButton.m @@ -0,0 +1,29 @@ +// +// VolumeButton.m +// Cog +// +// Created by Vincent Spader on 2/8/09. +// Copyright 2009 __MyCompanyName__. All rights reserved. +// + +#import "VolumeButton.h" +#import "VolumeSlider.h" + +@implementation VolumeButton + +- (void)scrollWheel:(NSEvent *)theEvent +{ + [(VolumeSlider *)_popView showToolTipForDuration:1.0]; +} + +- (void)mouseDown:(NSEvent *)theEvent +{ + [(VolumeSlider *)_popView hideToolTip]; + + [super mouseDown:theEvent]; + + [(VolumeSlider *)_popView hideToolTip]; +} + + +@end diff --git a/Utils/VolumeSlider.h b/Utils/VolumeSlider.h new file mode 100644 index 000000000..7552fcfc1 --- /dev/null +++ b/Utils/VolumeSlider.h @@ -0,0 +1,20 @@ +// +// VolumeSlider.h +// Cog +// +// Created by Vincent Spader on 2/8/09. +// Copyright 2009 __MyCompanyName__. All rights reserved. +// + +#import +#import "ToolTipWindow.h" + +@interface VolumeSlider : NSSlider { + ToolTipWindow *toolTip; +} + +- (void)showToolTip; +- (void)showToolTipForDuration:(NSTimeInterval)duration; +- (void)hideToolTip; + +@end diff --git a/Utils/VolumeSlider.m b/Utils/VolumeSlider.m new file mode 100644 index 000000000..f4c27ebad --- /dev/null +++ b/Utils/VolumeSlider.m @@ -0,0 +1,87 @@ +// +// VolumeSlider.m +// Cog +// +// Created by Vincent Spader on 2/8/09. +// Copyright 2009 __MyCompanyName__. All rights reserved. +// + +#import "VolumeSlider.h" +#import "CogAudio/Helper.h" + +@implementation VolumeSlider + +- (id)initWithFrame:(NSRect)frame +{ + self = [super initWithFrame:frame]; + if (self) + { + toolTip = [[ToolTipWindow alloc] init]; + } + + return self; +} + +- (id)initWithCoder:(NSCoder *)coder +{ + self = [super initWithCoder:coder]; + if (self) + { + toolTip = [[ToolTipWindow alloc] init]; + } + + return self; +} + +- (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]; + + [text release]; +} + +- (void)showToolTip +{ + [self updateToolTip]; + + [toolTip orderFront]; +} + +- (void)showToolTipForDuration:(NSTimeInterval)duration +{ + [self updateToolTip]; + [toolTip orderFrontForDuration:duration]; +} + + +- (void)hideToolTip +{ + [toolTip close]; +} + + +- (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]; +} + + +@end