|
| 1 | +import { Project } from "@/core/Project"; |
| 2 | +import { Settings } from "@/core/service/Settings"; |
| 3 | + |
| 4 | +/** |
| 5 | + * 全局遮罩渲染器 |
| 6 | + */ |
| 7 | +export namespace GlobalMaskRenderer { |
| 8 | + /** |
| 9 | + * 渲染鼠标位置的圆形遮罩 |
| 10 | + * @param project |
| 11 | + * @param mouseLocation |
| 12 | + * @param reverse |
| 13 | + */ |
| 14 | + export function renderCircleMask(project: Project, mouseLocation: { x: number; y: number }, reverse = false) { |
| 15 | + if (Settings.isStealthModeEnabled) { |
| 16 | + const ctx = project.canvas.ctx; |
| 17 | + // 设置合成模式为目标输入模式 |
| 18 | + if (reverse) { |
| 19 | + ctx.globalCompositeOperation = "destination-out"; |
| 20 | + } else { |
| 21 | + ctx.globalCompositeOperation = "destination-in"; |
| 22 | + } |
| 23 | + // 获取鼠标位置 |
| 24 | + const mouseX = mouseLocation.x; |
| 25 | + const mouseY = mouseLocation.y; |
| 26 | + // 获取潜行模式半径 |
| 27 | + const scopeRadius = Settings.stealthModeScopeRadius; |
| 28 | + // 绘制圆形区域 |
| 29 | + ctx.beginPath(); |
| 30 | + ctx.arc(mouseX, mouseY, scopeRadius, 0, Math.PI * 2); |
| 31 | + ctx.fillStyle = "rgba(0, 0, 0, 1)"; // 设置填充颜色为完全不透明的黑色 |
| 32 | + ctx.fill(); |
| 33 | + // 恢复合成模式 |
| 34 | + ctx.globalCompositeOperation = "source-over"; |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | + /** |
| 39 | + * 渲染鼠标位置的正方形遮罩 |
| 40 | + * @param project |
| 41 | + * @param mouseLocation |
| 42 | + * @param reverse |
| 43 | + */ |
| 44 | + export function renderSquareMask(project: Project, mouseLocation: { x: number; y: number }, reverse = false) { |
| 45 | + if (Settings.isStealthModeEnabled) { |
| 46 | + const ctx = project.canvas.ctx; |
| 47 | + // 设置合成模式为目标输入模式 |
| 48 | + if (reverse) { |
| 49 | + ctx.globalCompositeOperation = "destination-out"; |
| 50 | + } else { |
| 51 | + ctx.globalCompositeOperation = "destination-in"; |
| 52 | + } |
| 53 | + // 获取鼠标位置 |
| 54 | + const mouseX = mouseLocation.x; |
| 55 | + const mouseY = mouseLocation.y; |
| 56 | + // 获取潜行模式半径作为正方形边长 |
| 57 | + const sideLength = Settings.stealthModeScopeRadius; |
| 58 | + // 计算正方形左上角坐标(以鼠标位置为中心) |
| 59 | + const squareX = mouseX - sideLength / 2; |
| 60 | + const squareY = mouseY - sideLength / 2; |
| 61 | + // 绘制正方形区域 |
| 62 | + ctx.beginPath(); |
| 63 | + ctx.rect(squareX, squareY, sideLength, sideLength); |
| 64 | + ctx.fillStyle = "rgba(0, 0, 0, 1)"; // 设置填充颜色为完全不透明的黑色 |
| 65 | + ctx.fill(); |
| 66 | + // 恢复合成模式 |
| 67 | + ctx.globalCompositeOperation = "source-over"; |
| 68 | + } |
| 69 | + } |
| 70 | +} |
0 commit comments