# mouse events in opengl # this illustrates: # * basic event handling using 'responder' # * display and model/view coordinate mapping # TEMP FIX (SDL NOT READY YET) ############### load-opengl-x11 ############################################## load-opengl 300 dup display 2d animation # we'll store the position and color vector here (0 0) eventco>vector variable! position (1. 1. 1.) variable! square-color # the motion event handler, will receive a list in the form of # ( ) representing the display coordinates relative to # the top left border. # the drag event handler is the same but when dragging events are routed. # the press/release event handler only change the color. : motion-event eventco>vector position ! 0. 0. 1. 3 pack square-color ! ; : drag-event eventco>vector position ! 1. 0. 0. 3 pack square-color ! ; : pressrelease-event drop 0. 1. 0. 3 pack square-color ! ; : handle-event split # ( ...) -- (...) # route events according to tag. the word it routes to gets # only the payload. # TAG HANDLER ` motion route motion-event ` drag route drag-event ` press route pressrelease-event ` release route pressrelease-event unsplit # put back together drop # ignore the rest ; # in the animation loop, we get the position stored by the event # handler, and transform it to model/view coordinates. # the color of the square, stored in a variable, is updated at the # same time. : animate position @ # get last position stored my event handler event-tx-matrix # get the current transform matrix for event coords * # apply transformation trans # use the result to just translate to the point square-color @ # call the stored rgb value unpack rgb .1 square ; # register the handler and the drawing routine ' handle-event is responder ' animate is drawer interactive # note that 'event-tx-matrix' uses the opengl modelview matrix, so it # is only valid during an active animation. if you run the word at a # console, it will most probably contain garbage.