Example

Mouse Move Events - Raw Over and Hover Events

Author: Carl Sassenrath
This example requires REBOL/View
Return to REBOL Cookbook

This simple example illustrates how a program can track the mouse move events in REBOL. This is useful if you need to make your own over and hover types of graphical user interface actions.

Here is a layout that shows a BOX that is 200x200 in size. The code also sets a new OVER feel for the box that will show the location of the mouse as text in the box. Also, if the mouse moves into the box, the box will turn green. If the mouse moves out of the box, the box will turn red. (The action value indicates those changes.)


    out: layout [
        origin 0x0
        box 200x200 "Mouse Move Tracker" feel [
            over: func [face action offset] [
                face/text: form offset
                face/color: either action [leaf][maroon]
                show face
            ]
        ]
    ]

If you VIEW the layout with:


    view out

you will only see the OVER function get called when the mouse moves into or out of the box (called a transition event). This is done automatically to reduce the amount of computing that happens as you move your mouse around a window.

If you want to get OVER events for every mouse move, add the ALL-OVER option to the window when you VIEW it:


    view/options out [all-over]

Now you can see every mouse move. This feature can be useful for games and special utilities than need to continuously detect over and hover types of actions.


2006 REBOL Technologies REBOL.com REBOL.net