/* FineSlider.m		by Mike Gravina		December 1991
 * A subclass of Slider that allows Alternate key to slow slider 
 * down by scale factor
 *
 * Copyright (C)  1991  The Board of Trustees of
 * The Leland Stanford Junior University.  All Rights Reserved.
 */
 
#import "FineSlider.h"

const char FineSlider_h_rcsid[] = FINESLIDER_H_ID;
const char FineSlider_m_rcsid[] = "$Id: FineSlider.m,v 1.4 1991/12/24 14:37:00 pfkeb Rel $";


#import <appkit/Application.h>

@implementation FineSlider
+ new
{
    self = [super new];
    inAltSequence = NO;
    offset = 0.0;
    scaleFactor = 20.0;
    return self;
}


- (float) floatValue
{
    NXEvent            *thisEvent;
    float               newValue;

    newValue = [super floatValue];
    thisEvent = [NXApp currentEvent];
    if (thisEvent->flags & NX_ALTERNATEMASK) {
	if (!inAltSequence) {
	    inAltSequence = YES;
	    centerValue = newValue - offset;	/* save rubberband end point */
	    returnValue = centerValue;
	} else {
	    returnValue = centerValue + (newValue - centerValue) / scaleFactor;
	    offset = newValue - returnValue;	/* save rubberband's new
						 * length */
	}
    } else {
	inAltSequence = NO;
	returnValue = newValue - offset;	/* rubberband treated as
						 * rigid */
    }
    if (thisEvent->type == NX_LMOUSEUP) {
	centerValue = returnValue;	/* set rubberband end point to
					 * current point */
	offset = 0.0;		/* set rubberband length to zero */
    }
    [super setFloatValue:returnValue];
    return returnValue;
}

- setScaleFactor:(float) aFloat
{
    scaleFactor = aFloat;
    return self;
}
@end
