From cc737578baa0dadef5c2b82b6ada66c117ba3d6b Mon Sep 17 00:00:00 2001 From: walker Date: Fri, 1 Sep 2023 17:12:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=86=8D=E8=B0=83=E6=95=B4=E5=AF=B9=E6=AF=94?= =?UTF-8?q?=E8=89=B2=E7=AE=97=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/jlgraphic/plugins/CommonMousePlugin.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/jlgraphic/plugins/CommonMousePlugin.ts b/src/jlgraphic/plugins/CommonMousePlugin.ts index 8ca6ce7..76993ff 100644 --- a/src/jlgraphic/plugins/CommonMousePlugin.ts +++ b/src/jlgraphic/plugins/CommonMousePlugin.ts @@ -101,13 +101,26 @@ export class CommonMouseTool extends AppInteractionPlugin { return new CommonMouseTool(app); } + /** + * 计算对比色 + * @param rgb + * @returns + */ + private calContrastColor(rgb: number): number { + if (rgb > 0.45 && rgb < 0.55) { + return 0; + } else { + return 1 - rgb; + } + } + private updateBoxLineColor(cp: ICanvasProperties) { // 根据画布背景调整线色 const color = new Color(cp.backgroundColor); // 对比色 - const r = 1 - color.red; - const g = 1 - color.green; - const b = 1 - color.blue; + const r = this.calContrastColor(color.red); + const g = this.calContrastColor(color.green); + const b = this.calContrastColor(color.blue); this._boxLineColor.setValue([r, g, b]); }