Processes mouse events to either (1) directly move a DisplayObject or (2) forward events to an EventHandler.

(1) MouseTracker moves the DisplayObject directly when:

  • No EventHandler is specified.

  • dragDispObj does not have a SimObject. Examples include DisplayClock and EnergyBarGraph.

  • dragDispObj has a SimObject but it is not recognized by the EventHandler. An EventHandler indicates that it doesn't recognize a SimObject by returning false from EventHandler.startDrag. An example scenario is a dragable marker object which the user can position as desired.

(2) Events are sent to the EventHandler when:

  • dragDispObj has a SimObject which is recognized by the EventHandler. An EventHandler indicates that it recognizes a SimObject by returning true from EventHandler.startDrag. In this case, events are translated to simulation coordinates for the SimView that the DisplayObject is in.

  • dragDispObj is null. In this case, events are translated to simulation coordinates of the specified SimView.

See Mouse Events in SimController.

TO DO what to do when there are multiple SimObjects, as with DisplayPath?

TO DO Make a unit test; especially for findNearestDragable. Note that it is possible to make synthetic events for testing in Javascript.


  • Parameters

    • dragDispObj: null | DisplayObject

      the dragable DisplayObject to move according to mouse movements; null indicates that events will just be translated to simulation coordinates

    • view: SimView

      the SimView that the DisplayObject is in; or the SimView to use for translating to simulation coordinates when there is no DisplayObject

    • loc_sim: Vector

      location of initial mouse event in simulation coordinates of view

    • drag_body: null | Vector

      location of 'drag point' on the SimObject in body coordinates of the SimObject; this is where for example a spring will be attached on the SimObject when dragging; will be null when no SimObject was found

    • eventHandler: null | EventHandler

      the EventHandler to send events to; will be null when a DisplayObject should be dragged directly

    Returns MouseTracker


dragDispObj_: null | DisplayObject

the DisplayObject currently being dragged.

dragOffset_: Vector = Vector.ORIGIN

the offset between the dragable DisplayObject's initial position and the initial mouse click, in simulation coordinates.

dragSimObj_: null | SimObject = null

The SimObject being dragged (the SimObject being displayed by dragDispObj_) if no SimObject found, send the x, y coords of the click anyway, with simObj=null

drag_body_: null | Vector

location of drag point in body coordinates of the SimObject; ignored when there is no SimObject

ehDrag_: boolean = false

true when EventHandler is dragging a SimObject

loc_sim_: Vector

location of mouse event in SimView's simulation coords

view_: SimView

the SimView to search for dragable objects


  • Called when a mouse move event occurs.


    • loc_screen: Vector

      location of the event in screen coordinates

    Returns void

  • Finds the nearest dragable DisplayObject to the starting location (using distance in screen coordinates), and creates a MouseTracker for dragging it. If no dragable DisplayObject is found, creates a MouseTracker which translates mouse events to simulation coordinates of the LabCanvas's focus view.

    Searches all the SimView's of the LabCanvas, in front to back order. When a DisplayObject has no SimObject, then regard it as an 'opaque' object and immediately accept it as the target if mouse is inside; or ignore it entirely if mouse is outside. We search from front to back in visual order, so that objects that are visually 'on top' are checked first.


    • labCanvas: LabCanvas

      the LabCanvas to process events for

    • start_screen: Vector

      mouse down location in LabCanvas screen coords

    • eventHandler: null | EventHandler

      the EventHandler to send mouse events to, or null

    Returns null | MouseTracker

    the MouseTracker to use for processing mouse events, or null if MouseTracking is not possible

Generated using TypeDoc