Oy.
After 3 more hours of futzing, I can't get the knob to center on
the slider bar without leaving part of itself behind when it
moves. Anyone see what I'm doing wrong here?
Here's the draw knob method:
- (void) drawKnob:(NSRect) knobRect
{
float adjustedLeft = knobRect.origin.x,
knobWidth = knobRect.size.width,
knobHeight = knobRect.size.height,
maxRight = maxXOrigin - knobWidth;
if ((adjustedLeft) < 10)
adjustedLeft = 10;
else if (adjustedLeft > maxRight)
adjustedLeft = maxRight;
adjustedKnobRect = NSMakeRect(adjustedLeft,
knobRect.origin.y, knobWidth, knobHeight);
// following line centers the knob correctly,
// but when you drag it, half of the pixels are
// left behind
/*if (isFlipped)
adjustedRect.origin.y += 4;*/
[gSliderKnob drawInRect: adjustedKnobRect
fromRect: NSZeroRect
operation: NSCompositeSourceOver
fraction: 1.0];
}
And here's the other draw stuff in case that sheds light on the
problem
- (void) drawBarInside:(NSRect) inRect
flipped:(BOOL) inFlipped
{
// may need this for knob drawing
isFlipped = inFlipped;
// update the rectangles for the slider rail
[self updateGeometryWithFrame: inRect];
// draw control images
[gSliderBackgroundImage drawInRect: inRect
fromRect: NSZeroRect
operation: NSCompositeSourceOver
fraction: 1.0];
[gSliderTrackLeft drawInRect: leftRect
fromRect: NSZeroRect
operation: NSCompositeSourceOver
fraction: 1.0];
[gSliderTrackCenter drawInRect: middleRect
fromRect: NSZeroRect
operation: NSCompositeSourceOver
fraction: 1.0];
[gSliderTrackRight drawInRect: rightRect
fromRect: NSZeroRect
operation: NSCompositeSourceOver
fraction: 1.0];
[self drawKnob];
}
- (void) updateGeometryWithFrame:(NSRect) inFrame
{
adjustedSliderRect = NSMakeRect(inFrame.origin.x + 10, 0,
inFrame.size.width - 20, inFrame.size.height);
float rectHeight = inFrame.size.height,
leftWidth = [gSliderTrackLeft size].width,
rightWidth = [gSliderTrackRight
size].width,
centerWidth = adjustedSliderRect.size.width
- leftWidth - rightWidth,
yOffset = (rectHeight -
DefaultSliderBarHeight) / 2;
adjustedRight = adjustedSliderRect.origin.x +
adjustedSliderRect.size.width;
leftRect = NSMakeRect(adjustedSliderRect.origin.x,
yOffset, leftWidth, DefaultSliderBarHeight);
rightRect = NSMakeRect(adjustedRight - rightWidth,
yOffset, rightWidth, DefaultSliderBarHeight);
middleRect = NSMakeRect(leftRect.origin.x +
leftRect.size.width, yOffset, centerWidth, DefaultSliderBarHeight);
minXOrigin = 10;
maxXOrigin = adjustedRight;
}
- (BOOL)_usesCustomTrackImage
{
return YES;
}
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
40ardendo.se
This email sent to email@hidden