Hi,

I am using the following two methods for a scrolling number box which is essentially a slider in the form of a NSTextField subclass. I have yet to implement this for my custom sliders but maybe this is a good starting point for you? When I first dabbled with custom sliders all I did was override the mouseUp, mouseDown, mouseDragged methods etc now my custom sliders are subclasses of NSControl rather than NSSlider.

-(void)mouseUp:(NSEvent*)theEvent
{
        if(drag) drag = NO;
}

-(void)mouseDragged:(NSEvent*)theEvent
{
        float val = [self floatValue];
        
        if(!drag) {
// float start_x = [self convertPoint: [theEvent locationInWindow] fromView: nil].x; start_y = [self convertPoint:[theEvent locationInWindow] fromView: nil].y;
                prev_y = start_y;
                drag = YES;
        };
                
        // key modifier key flags
        unsigned int flags;
        flags = [theEvent modifierFlags];
        
float next_y = [self convertPoint:[theEvent locationInWindow] fromView: nil].y;
        float deltaY = (next_y - prev_y) / dragSize;
        prev_y = next_y;
        
        if(flags & NSAlternateKeyMask) deltaY *= fineGrain;
        val += range * deltaY;
        
        [self checkBounds:&val];
        [self setFloatValue:val];
        
        // continuously send the action
        [self sendAction:(SEL)[self action] to:(id)[self target]];
}

Hope that helps,
Stephen


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

Le 23 juil. 09 à 21:09, livinginlosange...@mac.com 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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/stephen.blinkhorn%40audiospillage.com

This email sent to stephen.blinkh...@audiospillage.com

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to