githubEdit

Interacting with elements

Once an element has been drawn it sets multiple parts of global state that can then be read by the osl program. These are predominantly focused on the mouse pointer.

mouse_touching

this is a boolean of if the mouse is over the current element

clicked

this is a boolean of if mouse_touching is true and the left mouse button is held.

onclick

this is a boolean of if mouse_touching is true and is only true on the first frame of the left mouse button being clicked

mouse_x

this is a number of the x position of the mouse normalised to the current rendering context's origin point

mouse_y

this is a number of the y position of the mouse normalised to the current rendering context's origin point

Examples

Here is how you would use onclick . All other state variables are used in very similar ways.

// draw a white square
square 100 100 : c#fff

// check if the square is clicked
if onclick (
  log "i was clicked!"
  // this only fires when the user clicks the square
)

You can also make a square that goes to the mouse pointer using the goto x y command

// go to the mouse pointer's position
goto mouse_x mouse_y
// draw a white square
square 100 100 : c#fff

You can use mouse_touching to do hover effects

Last updated