Custom NSSlider Action Not Firing
Custom NSSlider Action Not Firing
- Subject: Custom NSSlider Action Not Firing
- From: Austin Sarner <email@hidden>
- Date: Sun, 10 Jul 2005 21:49:54 -0400
Hello all,
I've created a subclass of NSSlider that uses the metal image (see
the iTunes volume slider). My problem is that the slider's action is
not firing -- while the same action fires if I simply use NSSlider
instead of the custom subclass. I would greatly appreciate any
assistance you could provide. Below is the code for the subclass.
/* MetalSlider */
#import <Cocoa/Cocoa.h>
#import "MetalSliderCell.h"
@interface MetalSlider : NSSlider
{
}
@end
#import "MetalSlider.h"
@implementation MetalSlider
- (void)awakeFromNib
{
MetalSliderCell * aCell = [[[MetalSliderCell alloc] init] retain];
[aCell setControlSize:NSSmallControlSize];
[self setCell:aCell];
[aCell release];
}
/* MetalSliderCell */
#import <Cocoa/Cocoa.h>
@interface MetalSliderCell : NSSliderCell
{
BOOL isDown;
}
@end
#import "MetalSliderCell.h"
static NSImage * _knobOff;
static NSImage * _knobOn;
@implementation MetalSliderCell
-(id)init
{
self = [super init];
_knobOff = [[NSImage imageNamed:@"metalSliderKnobInactive"]
retain];
_knobOn = [[NSImage imageNamed:@"metalSliderKnobActive"]
retain];
return self;
}
- (void)drawKnob:(NSRect)knobRect
{
NSImage * knob;
if (isDown)
knob = _knobOn;
else
knob = _knobOff;
[[self controlView] lockFocus];
[knob compositeToPoint:NSMakePoint(knobRect.origin.x
+1,knobRect.origin.y+knobRect.size.height-2)
operation:NSCompositeSourceOver];
[[self controlView] unlockFocus];
}
- (void)stopTracking:(NSPoint)lastPoint at:(NSPoint)stopPoint inView:
(NSView *)controlView mouseIsUp:(BOOL)flag
{
isDown = NO;
[self drawKnob];
[super stopTracking:lastPoint at:stopPoint inView:controlView
mouseIsUp:flag];
}
- (BOOL)startTrackingAt:(NSPoint)startPoint inView:(NSView *)controlView
{
isDown = YES;
[self drawKnob];
return [super startTrackingAt:startPoint inView:controlView];
}
@end
--------------------
Austin Sarner
Neometric Software (http://neometricsw.com)
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden