Demo window 3. Getting click locations

You can use the functions demoX and demoY to see where the user has clicked. These functions respond in world coordinates. To see whether the user has clicked in the sound that occupies the upper half of the screen in the above example, you do for instance

    while demoWaitForInput ()
        if demoClicked ()
            demo Select outer viewport: 0, 100, 50, 100
            demo Axes: 0, 3, -1, 1
            if demoX () >= 0 and demoX () < 3 and demoY () >= -1 and demoY () < 1

The last line can be shortened to:

            if demoClickedIn (0, 3, -1, 1)

Another example of when you want to know the click location is when you test for a click on a button that you drew on the screen:

    demo Paint rounded rectangle: “pink”, 30, 70, 16, 24
    demo Text: 50, “centre”, 20, “half”, “Analyse”
    while demoWaitForInput ()
        goto ANALYSE demoClickedIn (30, 70, 16, 24)

Links to this page


© Paul Boersma 2009-2023