Skip to content

Commit

Permalink
fix(color-picker): alpha-channel slider scope updates to reflect curr…
Browse files Browse the repository at this point in the history
…ent opacity (#8700)

**Related Issue:** #7761

## Summary

When using the alpha-channel slider, the scope now updates to reflect
the current opacity.
  • Loading branch information
Elijbet authored Feb 8, 2024
1 parent 1d1b933 commit cd0b532
Showing 1 changed file with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1382,7 +1382,7 @@ export class ColorPicker
this.colorFieldScopeTop = y;
});

this.drawThumb(this.colorFieldRenderingContext, radius, x, y, hsvColor);
this.drawThumb(this.colorFieldRenderingContext, radius, x, y, hsvColor, false);
}

private drawThumb(
Expand All @@ -1391,6 +1391,7 @@ export class ColorPicker
x: number,
y: number,
color: Color,
applyAlpha: boolean,
): void {
const startAngle = 0;
const endAngle = 2 * Math.PI;
Expand All @@ -1400,14 +1401,28 @@ export class ColorPicker
context.arc(x, y, radius, startAngle, endAngle);
context.fillStyle = "#fff";
context.fill();

context.strokeStyle = "rgba(0,0,0,0.3)";
context.lineWidth = outlineWidth;
context.stroke();

if (applyAlpha && color.alpha() < 1) {
const pattern = context.createPattern(this.getCheckeredBackgroundPattern(), "repeat");
context.beginPath();
context.arc(x, y, radius - 3, startAngle, endAngle);
context.fillStyle = pattern;
context.fill();
}

context.globalCompositeOperation = "source-atop";

context.beginPath();
context.arc(x, y, radius - 3, startAngle, endAngle);
context.fillStyle = color.rgb().alpha(1).string();
const alpha = applyAlpha ? color.alpha() : 1;
context.fillStyle = color.rgb().alpha(alpha).string();
context.fill();

context.globalCompositeOperation = "source-over";
}

private drawActiveHueSliderColor(): void {
Expand All @@ -1434,7 +1449,7 @@ export class ColorPicker
this.hueScopeLeft = sliderBoundX;
});

this.drawThumb(this.hueSliderRenderingContext, radius, sliderBoundX, y, hsvColor);
this.drawThumb(this.hueSliderRenderingContext, radius, sliderBoundX, y, hsvColor, false);
}

private drawHueSlider(): void {
Expand Down Expand Up @@ -1589,7 +1604,7 @@ export class ColorPicker
this.opacityScopeLeft = sliderBoundX;
});

this.drawThumb(this.opacitySliderRenderingContext, radius, sliderBoundX, y, hsvColor);
this.drawThumb(this.opacitySliderRenderingContext, radius, sliderBoundX, y, hsvColor, true);
}

private getSliderBoundX(x: number, width: number, radius: number): number {
Expand Down

0 comments on commit cd0b532

Please sign in to comment.