Re: drawKnob in NSSliderCell subclass
Re: drawKnob in NSSliderCell subclass
- Subject: Re: drawKnob in NSSliderCell subclass
- From: "Christoph Teschner" <email@hidden>
- Date: Sat, 20 May 2006 03:18:46 +0200
Hi,
I finally got my custom slider working, except that at the left and right
end of the slider the the outer parts of the slider knob are cut off. When
the knob is in the middle of the slider everything works.
Here is my current code. Any advice would be appreciated.
@implementation MySlider
- (void)awakeFromNib {
NSCell *oldCell = [self cell];
MySliderCell * aCell = [[[MySliderCell alloc] init] retain];
[aCell setAction:[oldCell action]];
[aCell setTarget:[oldCell target]];
[self setCell:aCell];
[aCell release];
//resize frame size
NSRect myFrame = [self frame];
myFrame.size.height = [[NSImage imageNamed:@"square.tif" ] size].height;
[self setFrame:myFrame];
}
@end
@implementation MySliderCell
-(id)init {
self = [super init];
knobImage = [[NSImage imageNamed:@"square.tif" ]retain];
return self;
}
- (void)drawKnob:(NSRect)knobRect{
[[self controlView] lockFocus];
[knobImage compositeToPoint:NSMakePoint(knobRect.origin.x
,knobRect.origin.y+knobRect.size.height) operation:NSCompositeSourceOver];
[[self controlView] unlockFocus];
}
- (NSRect)knobRectFlipped:(BOOL)flipped{
NSRect myRect = [super knobRectFlipped:flipped];
myRect.origin.y -= ([knobImage size].height - myRect.size.height) / 2;
myRect.origin.x -= ([knobImage size].width - myRect.size.width) / 2;
myRect.size = [knobImage size];
return myRect;
}
@end
Thanks a lot
Christoph
From: Lon Giese <email@hidden>
To: "Christoph Teschner" <email@hidden>
Subject: Re: drawKnob in NSSliderCell subclass
Date: Wed, 17 May 2006 21:41:10 -0700
You have to call - (void)sizeToFit, nothing is going to call it especially
not after awakeFromNib, all widgets have already been unarchived the
slider was sized in the nib already...
call sizeToFit in awakeFromNib after setting the cell if that doesn't size
it properly then try the following instead
in the sliders awakeFrom Nib you make the frame big enough to show the
knob
- (NSRect)frame
- (void)setFrame:(NSRect)frameRect
Call frame first to get the current frame rect, add a little to it and
then call setFrame:...
you might need to call setNeedsDisplay. also but probably not cause you're
changing the frame in the awakeFromNib and its not displayed yet anyway.
On May 17, 2006, at 8:19 PM, Christoph Teschner wrote:
Hi,
I was not quite sure where to put the empty sizeToFit, so I put it in my
sliderCell and in my slider (both with logs), but non of them even get
called. I have no idea what's going wrong. When should the sizeToFit be
called? Here is my current code, perhaps you see what I am doing wrong:
@implementation MySliderCell
-(id)init {
self = [super init];
knobImage = [[NSImage imageNamed:@"GotoEnd.tif" ]retain];
return self;
}
- (void)sizeToFit {NSLog(@"SizeToFit in MySliderCell");}
- (void)drawKnob:(NSRect)knobRect {
[[self controlView] lockFocus];
[knobImage compositeToPoint:
NSMakePoint(knobRect.origin.x,knobRect.origin.y+knobRect.size.height)
operation:NSCompositeSourceOver];
[[self controlView] unlockFocus];
}
- (void)awakeFromNib {
NSCell *oldCell = [self cell];
MySliderCell * aCell = [[[MySliderCell alloc] init] retain];
[aCell setAction:[oldCell action]];
[aCell setTarget:[oldCell target]];
[self setCell:aCell];
[aCell release];
}
- (void)sizeToFit {NSLog(@"SizeToFit in MySlider");}
Thank you for your help!
Christoph
From: George Orthwein <email@hidden>
To: Christoph Teschner <email@hidden>
CC: email@hidden, email@hidden
Subject: Re: drawKnob in NSSliderCell subclass
Date: Wed, 17 May 2006 21:57:22 -0400
It looks like all you need is an empty sizeToFit...
http://www.cocoabuilder.com/archive/message/cocoa/2004/9/17/117721
http://www.cocoabuilder.com/archive/message/cocoa/2005/4/1/132006
George
_______________________________________________
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
_______________________________________________
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