views:

95

answers:

1

I am not sure how to phrase this better as a title but I need to make an NSSlider that functions as a normal volume knob. At the moment it will spin around as many times as I hold the mouse down and move it around the control. I need it to stop at the "0" position and the "100" position, I cannot have it jumping from 0 to 100 when I drag it the other way. I hope I am making this clear. Does anyone know how to do this or have any suggestions?

A: 

I think you'll need to subclass NSSliderCell and override startTrackingAt:inView:, continueTracking:at:inView: and stopTracking:at:inView:mouseIsUp:.

The documentation of continueTracking:at:inView: says:

This method is invoked in trackMouse:inRect:ofView:untilMouseUp:. The default implementation returns YES if the cell is set to continuously send action messages to its target when the mouse button is down or the mouse is being dragged. Subclasses can override this method to provide more sophisticated tracking behavior.

NSResponder
This is a good place to look, thank you for the suggestion. Unfortunately this does not quite do it. The problem is that I do not want to stop tracking the mouse movement, I just don't want the mouse movement to influence the control if it has moved past a certain point. I was able to make something work by just returning NO if we are tracking past the center line with continueTracking:at:inView: but this does not give the expected behavior. I think the only way of really making this do what I want it to would be to write my own control but we have gone back to the normal slider for now.
Andrew