Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set alpha value for Transparent clickthrough window #8200

Open
bmatusiak opened this issue Jul 24, 2024 · 2 comments
Open

set alpha value for Transparent clickthrough window #8200

bmatusiak opened this issue Jul 24, 2024 · 2 comments

Comments

@bmatusiak
Copy link

I would like to create a drawing tracing app to overlay on top of MSPaint or any image drawing editor..

the problem is,, alpha needs to be 0 for current clickthrough https://nwjs.readthedocs.io/en/latest/For%20Users/Advanced/Transparent%20Window/

i would like the opposite, i want to have clickthrough windows, for anything where value is not 1. not clickthrough if its 1/solid. if it has any transparent alpha other then 1/solid, then its clickthrough

this would allow me to overlay anything on a canvas to trace in another drawing app. or to create overlay HUDs that don't block the mouse

@bmatusiak
Copy link
Author

bmatusiak commented Jul 24, 2024

my only current option is to, set the alpha to 0 at the pixel where the current mouse position is on the canvas. and its buggy to do it in this way

however this does not work with elements like TEXT elements.

@bmatusiak
Copy link
Author

current workaround,

<html>
<head>
</head>
<body>
    <script>
        window.onload = () => {
            var newgui = require('nw.gui');
            var newWindow = newgui.Window.open('other.html', {
                position: 'center',
                width: 600,
                height: 800,
                frame: false,
                transparent: true,
                always_on_top: true
            }, function (win) {
                win.show();
            });

        }
    </script>
</body>
</html>
<html>
<head>
    <style>
        html,
        body {
            background-color: rgba(0, 255, 0, 0);
            padding: 0;
            margin: 0;
            border: 0;
            width: 100%;
            height: 100%;
        }
        canvas {
            width: 100%;
            height: 100%;
        }
    </style>
</head>
<body onload="javascript: start();">
    <canvas id="viewCanvas"></canvas>
    <script>
        function start() {
            var mousePOS;
            var canvas = document.getElementById("viewCanvas");
            canvas.addEventListener('mousemove', function (event) {
                const rect = canvas.getBoundingClientRect();
                const x = event.clientX - rect.left;
                const y = event.clientY - rect.top;
                mousePOS = { x, y };
            });
            function draw() {
                canvas.width = document.body.clientWidth;
                canvas.height = document.body.clientHeight;
                const ctx = canvas.getContext("2d");
                ctx.globalAlpha = 0.5;
                ctx.clearRect(0, 0, canvas.width, canvas.height); 
                ctx.beginPath();
                ctx.fillStyle = "rgb(0,0,0)";
                ctx.rect(0, 0, canvas.width, canvas.height);
                ctx.fill();
                if (mousePOS) {
                    var blockSize = 1;
                    ctx.clearRect(mousePOS.x - blockSize, mousePOS.y - blockSize, blockSize * 2, blockSize * 2); // clear canvas
                }
                window.requestAnimationFrame(draw);
            }
            window.requestAnimationFrame(draw);
        }
    </script>
</body>
</html>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants