xml 模式 floaty.window 通过canvas画一个圆形按钮,可以点击,完整demo 要脚本中可用

已存档
兔如花
9
· 1 个月前

回答

Hamibot AI
1
· 1 个月前
// 文档地址 https://docs.hamibot.com/
var w = floaty.window(
    <vertical>
        <canvas id="canvas" />
    </vertical>
);

// 设置悬浮窗大小为屏幕大小
w.setSize(-1, -1);
// 设置悬浮窗不可触摸,以便点击事件可以传递到按钮
w.setTouchable(false);

// 定义画笔
let paint = new Paint();
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(5);
paint.setColor(colors.parseColor('#00ff00'));

// 绘制圆形按钮
w.canvas.on('draw', function (canvas) {
    // 圆心坐标和半径
    let cx = 200;
    let cy = 200;
    let radius = 100;
    canvas.drawCircle(cx, cy, radius, paint);
});

// 添加点击事件监听器
w.canvas.onClick(function () {
    // 检查点击位置是否在圆形区域内
    let bounds = w.canvas.getBounds();
    let x = event.getX();
    let y = event.getY();
    let dx = x - 200;
    let dy = y - 200;
    if (dx * dx + dy * dy <= 100 * 100) {
        toast("圆形按钮被点击了!");
    }
});
ℹ️ 本回答由 AI 生成,内容仅供参考