• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSSliderCell question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSSliderCell question


  • Subject: Re: NSSliderCell question
  • From: Patrick Cusack <email@hidden>
  • Date: Thu, 23 Jul 2009 14:34:10 -0700

Thanks for your ideas!!!! Here is what I did:

Here is what I did. I set up KVO for the variable that I attached to my NSSliderCell. When I made any changes to the underlying variable, the obersever method would trigger. When you add an observer you can retrieve the old and new values from the change dictionary and derive your new value. I temporary suppressed kvo so the routine didn't infinitely recurse when I set the value using kvo compliant setters (look at _ignoreObservation). I also updated the slider using the setFloatValue method. This constrained the slider as well. Now when I press the command key, I query the current event using your idea for getting the current event, [NSApp currentEvent], in my oberve value method. This works sufficiently for my purposes.

Patrick

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id) object change:(NSDictionary *)change context:(void *)context
{
if([keyPath isEqualToString:@"val"]){
if (_ignoreObservation != YES) {
if(([[NSApp currentEvent] modifierFlags] & NSCommandKeyMask) == NSCommandKeyMask){
float _old = [[change valueForKey:@"old"] floatValue];
float _new = [[change valueForKey:@"new"]floatValue];
_ignoreObservation = YES;

if(_new > _old){
float newT = _old + ((_new - _old)/100);
[self setVal:[NSNumber numberWithFloat:newT]];
[mySlider setFloatValue:newT];
} else {
float newT = _old + ((_new - _old)/100);
[self setVal:[NSNumber numberWithFloat:newT]];
[mySlider setFloatValue:newT];
}
}
}
_ignoreObservation = NO;
}
}


On Jul 23, 2009, at 12:29 PM, Jean-Daniel Dupas wrote:

Le 23 juil. 09 à 21:09, email@hidden a écrit :

I am employing an NSSliderCell in my table view, and I want to slow down the rate of change or increase the resolution of change using a modifier key like commands as I drag. This is employed in a few audio programs to assist a mixer in fine tuning either volume or pan when mixing. Where do I start? I have bound my NSSliderCell to a NSNumber in my NSObjectController. Can anyone think of a way that I could modify the delta of change? Would I have to do this using a NSSliderCell subclass? Any thoughts?

Just an idea. (not tested at all)
A possibility may be to override setDoubleValue: or whatever is used to set the cell value, and check if the current event ([NSApp currentEvent]) is a drag with ctrl down, and if this is the case compute the delta between the current value and the new value and reduce it proportionally before calling the super implementation.



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >NSSliderCell question (From: email@hidden)
 >Re: NSSliderCell question (From: Jean-Daniel Dupas <email@hidden>)

  • Prev by Date: Re: iPhone List? - few questions
  • Next by Date: Re: Comparing NSImages
  • Previous by thread: Re: NSSliderCell question
  • Next by thread: Re: NSSliderCell question
  • Index(es):
    • Date
    • Thread