From fb8e0df87d10a68e813840a8fb7f9b8c1da68eb1 Mon Sep 17 00:00:00 2001 From: fan Date: Fri, 1 Sep 2023 17:15:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E6=A1=86=E6=9E=B6=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- graphic-pixi | 2 +- src/jl-graphic/plugins/CommonMousePlugin.ts | 22 ++++++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/graphic-pixi b/graphic-pixi index c66f841..cc73757 160000 --- a/graphic-pixi +++ b/graphic-pixi @@ -1 +1 @@ -Subproject commit c66f841526d22af7dcb8ce768ad96488f13468c3 +Subproject commit cc737578baa0dadef5c2b82b6ada66c117ba3d6b diff --git a/src/jl-graphic/plugins/CommonMousePlugin.ts b/src/jl-graphic/plugins/CommonMousePlugin.ts index 20eec59..76993ff 100644 --- a/src/jl-graphic/plugins/CommonMousePlugin.ts +++ b/src/jl-graphic/plugins/CommonMousePlugin.ts @@ -101,11 +101,27 @@ 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 cn = color.toNumber() ^ 0xffffff; - this._boxLineColor.setValue(cn); + // 对比色 + const r = this.calContrastColor(color.red); + const g = this.calContrastColor(color.green); + const b = this.calContrastColor(color.blue); + this._boxLineColor.setValue([r, g, b]); } bind(): void { @@ -305,7 +321,7 @@ export class CommonMouseTool extends AppInteractionPlugin { if (!this.drag) return; // 绘制框选矩形框 this.box.clear(); - this.box.lineStyle({ width: 1, color: this._boxLineColor }); + this.box.lineStyle({ width: 2, color: this._boxLineColor }); const dsx = end.x - start.x; const dsy = end.y - start.y; let { x, y } = start;