Git Product home page Git Product logo

Comments (2)

bmatusiak avatar bmatusiak commented on July 30, 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.

from nw.js.

bmatusiak avatar bmatusiak commented on July 30, 2024

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>

from nw.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.