2

NSSliderCell をカスタマイズしたいのですが、奇妙な不具合が発生しています。

これは次のようになります (ズーム):

ここに画像の説明を入力

それは問題なく描画されますが、ノブをドラッグすると、左のバーが奇妙に見え始めます (ノブの影の一部が前のフレームから残っているように見えます):

ここに画像の説明を入力

ノブをドラッグするのをやめると、スライダーは再び正常になります。

コードは次のとおりです。

@implementation VolumeSliderCell

NSImage *knobImage = nil;
NSImage *leftBarLeftCapImage = nil;
NSImage *leftBarFillImage = nil;
NSImage *rightBarFillImage = nil;
NSImage *rightBarRightCapImage = nil;

- (id)initWithCoder:(NSCoder *)coder
{
self = [super initWithCoder:coder];
if (self) {
    knobImage = [NSImage imageNamed:@"volume_knob.png"];
    leftBarLeftCapImage = [NSImage imageNamed:@"volume_leftbar_leftcap.png"];
    leftBarFillImage = [NSImage imageNamed:@"volume_leftbar_fill.png"];
    rightBarFillImage = [NSImage imageNamed:@"volume_rightbar_fill.png"];
    rightBarRightCapImage = [NSImage imageNamed:@"volume_rightbar_rightcap.png"];
}

return self;
}

- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
{
//NSRect cellFrame = [self controlView].bounds;
//[[self controlView] setNeedsDisplayInRect:cellFrame];

[self drawBarInside:cellFrame flipped:[controlView isFlipped]];
[self drawKnob:cellFrame];
}

- (void)drawKnob:(NSRect)knobRect
{
[NSGraphicsContext saveGraphicsState];

CGRect bounds = [self controlView].bounds;
CGFloat value = ([self doubleValue]  - [self minValue])/ ([self maxValue] - [self minValue]);
CGRect rect = CGRectMake(value * (bounds.size.width - [knobImage size].width), (bounds.size.height - [knobImage size].height) / 2, [knobImage size].width, [knobImage size].height);

[knobImage drawInRect:CGRectIntegral(rect)];

[NSGraphicsContext restoreGraphicsState];
}

- (void)drawBarInside:(NSRect)aRect flipped:(BOOL)flipped
{
[NSGraphicsContext saveGraphicsState];

CGRect bounds = [self controlView].bounds;
CGFloat value = ([self doubleValue]  - [self minValue])/ ([self maxValue] - [self minValue]);
CGRect leftRect = CGRectMake([knobImage size].width / 2, (bounds.size.height - [leftBarFillImage size].height) / 2, value * (bounds.size.width - [knobImage size].width), [leftBarFillImage size].height);
CGRect rightRect = CGRectMake(leftRect.origin.x + leftRect.size.width, (bounds.size.height - [leftBarFillImage size].height) / 2, bounds.size.width - (leftRect.origin.x + leftRect.size.width + [knobImage size].width / 2), [leftBarFillImage size].height);

if (rightRect.size.width < 0)
{
    rightRect.size.width = 0;
}

NSDrawThreePartImage(CGRectIntegral(leftRect), leftBarLeftCapImage, leftBarFillImage, nil, NO, NSCompositeSourceOver, 1.0, YES);
NSDrawThreePartImage(CGRectIntegral(rightRect), nil, rightBarFillImage, rightBarRightCapImage, NO, NSCompositeSourceOver, 1.0, YES);

[NSGraphicsContext restoreGraphicsState];
}

どうしたの?

4

0 に答える 0