How to resolve the algorithm Mouse position step by step in the Ring programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Mouse position step by step in the Ring programming language

Table of Contents

Problem Statement

Get the current location of the mouse cursor relative to the active window. Please specify if the window may be externally created.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Mouse position step by step in the Ring programming language

Source code in the ring programming language

Load "guilib.ring"

lPress = false
nX = 0
nY = 0

new qApp {

        win1 = new qWidget()
        {

                setWindowTitle("Move this label!")
                setGeometry(100,100,400,400)
                setstylesheet("background-color:white;")

                Label1 = new qLabel(Win1){
                        setGeometry(100,100,200,50)
                        setText("Welcome")
                        setstylesheet("font-size: 30pt")
                        myfilter = new qallevents(label1)
                        myfilter.setEnterevent("pEnter()")
                        myfilter.setLeaveevent("pLeave()")
                        myfilter.setMouseButtonPressEvent("pPress()")
                        myfilter.setMouseButtonReleaseEvent("pRelease()")                                                               myfilter.setMouseMoveEvent("pMove()")
                        installeventfilter(myfilter)
                }

                show()
        }

        exec()
}

Func pEnter
        Label1.setStyleSheet("background-color: purple; color:white;font-size: 30pt;")

Func pLeave
        Label1.setStyleSheet("background-color: white; color:black;font-size: 30pt;")

Func pPress
        lPress = True
        nX = myfilter.getglobalx()
        ny = myfilter.getglobaly()

Func pRelease
        lPress = False
        pEnter()

Func pMove
        nX2 = myfilter.getglobalx()
        ny2 = myfilter.getglobaly()
        ndiffx = nX2 - nX
        ndiffy = nY2 - nY
        if lPress
                Label1 {
                        move(x()+ndiffx,y()+ndiffy)
                        setStyleSheet("background-color: Green;
                                 color:white;font-size: 30pt;")
                        nX = nX2
                        ny = nY2
                }
        ok

  

You may also check:How to resolve the algorithm Happy numbers step by step in the LOLCODE programming language
You may also check:How to resolve the algorithm ISBN13 check digit step by step in the Red programming language
You may also check:How to resolve the algorithm Keyboard input/Flush the keyboard buffer step by step in the Oforth programming language
You may also check:How to resolve the algorithm Tau function step by step in the Mathematica/Wolfram Language programming language
You may also check:How to resolve the algorithm Smarandache prime-digital sequence step by step in the Ruby programming language