Auto Mouse

<script src="./point_src/automouse"></script>

Automouse provides a point at the mouse position. It's the last known position of the mouse; updated upon mousemove.

let point = Point.mouse.position
Meta Data
title Auto Mouse
dependencies ()
unused_keys ()
unknown_keys ('tags',)
tags ['mouse']
filepath_exists True
path automouse
filepath automouse.js
clean_files ()

  • VariableDeclaration
    const

    getLastMousePos

    =
    function ( )
  • ClassDeclaration
    class comments:

    The AutoMouse class cares for much of the mouse pointer functionality for a stage and the a point. It's functionality is designed to hook onto preparing stages and their canvas. It exists as a singleton autoMouse:

    autoMouse = new AutoMouse()
    autoMouse == stage.mouse
    Point.mouse == stage.mouse
    

    Initiate like this:

    Point.mouse?.mount(stage.canvas)
    

    Synonymous to:

    installCanvas(canvas, stage){
        this.canvasMap.set(canvas, stage)
        Point.mouse?.listen(canvas)
    }
    
    • constructor

      constructor

      (
      parentClass
      )
      from AutoMouse
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      The AutoMouse constructor accepts undefined or a parentClass, a class entity:

      const autoMouse = new AutoMouse(Point)
      

      this instance will immediately announce itself using this._announce()

    • method

      _announce

      (
      )
      from AutoMouse
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Wait for a stage prep event and emit addon:announce with this instance as the target.

      This method is called automatically upon instantiation

    • method

      stagePrepareHandler

      (
      ev
      )
      from AutoMouse
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      The given event has a stage ready for mounting. Perform any changes, such as adding a reference to the mouse.

      console.log('AutoMouse::stagePrepareHandler', d)

    • method

      announcementResponse

      (
      ev , log = True
      )
      from AutoMouse
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])
    • method

      getMousePos

      (
      canvas
      )
      from AutoMouse
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Return the current X/Y, relative to the bounding client for the mouse, using the mouse cache.

      let mouseXY = autoMouse.getMousePos()
      
    • get

      xy

      (
      )
      from AutoMouse
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])
    • get

      position

      (
      )
      from AutoMouse
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      The this.position method returns a new Point, with the mouse XY (from the last motion).

      let mousePoint = autoMouse.position
      mousePoint.pen.fill(ctx)
      

      Use this.point for a persistent single Point instance.

    • get

      point

      (
      )
      from AutoMouse
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Return a persistent point, of which is updated rather than replaced when the mouse state changes.

    • method

      getBoundingClientRect

      (
      canvas
      )
      from AutoMouse
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Return the bounding box of the target canvas. If no canvas is given, the internal this.canvas is used.

      this.getBoundingClientRect() == this.canvas.getBoundingClientRect()
      
    • method

      getListenerMethods

      (
      )
      from AutoMouse
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      console.log('Setting up mouse events')

    • method

      mount

      (
      canvas
      )
      from AutoMouse
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Call upon mount to initate listening of all events on a canvas.

    • method

      listen

      (
      canvas , eventName , handler , opts
      )
      from AutoMouse
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])
    • method

      mousemoveHandler

      (
      canvas , event
      )
      from AutoMouse
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      let bound = this.getBoundingClientRect();

    • method

      callHandlers

      (
      name , canvas , event
      )
      from AutoMouse
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])
    • method

      mousedownHandler

      (
      canvas , event
      )
      from AutoMouse
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])
    • method

      mouseupHandler

      (
      canvas , event
      )
      from AutoMouse
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])
    • method

      applyPositionIncrement

      (
      space , event
      )
      from AutoMouse
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])
    • method

      wheelHandler

      (
      canvas , event
      )
      from AutoMouse
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])
    • method

      isDown

      (
      index
      )
      from AutoMouse
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])
    • method

      wheelSize

      (
      abs
      )
      from AutoMouse
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      (v * v)

    • method

      clampWheelSize

      (
      min , max , abs
      )
      from AutoMouse
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      A function to help clamp the wheel scroll within a range. By using this function, the wheel value doesn't exceed the clamp.

      let size = mouse.clampWheelSize(5, 20)
      

      The same can be done with the clamp function

      let size = clamp(mouse.wheelSize(), 30, 300)
      

      but when the wheel exceeds the clamp, it'll scroll into an unused range.

    • method

      on

      (
      canvas , name , handler , opts
      )
      from AutoMouse
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])
    • method

      getActionSpace

      (
      name , defaults = {}
      )
      from AutoMouse
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])
    • method

      speed

      (
      previous , delta = 1
      )
      from AutoMouse
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      Return the speed of the point over a delta. This is a lot like the velocity functionality, but cut-down for efficiency.

    • property

      _moduloTicker

      = 0
      from AutoMouse
      dict_keys(['kind', 'word', 'computed', 'static', 'value', 'type', 'pos', 'class_name'])
    • method

      modulatedSpeed

      (
      mod = 15 , previous , delta = 1
      )
      from AutoMouse
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])
    • method

      computeSpeed

      (
      previous , current , delta = 1
      )
      from AutoMouse
      dict_keys(['kind', 'word', 'static', 'computed', 'is_symbol', 'value', 'type', 'comments', 'pos', 'class_name'])

      CREATE use a smoothtext function share for this anf fps text

    dict_keys(['kind', 'word', 'parentName', 'type', 'body', 'comments', 'pos'])
  • ExpressionStatement

    :

    dict_keys(['type', 'expression', 'pos'])
  • VariableDeclaration
    const

    autoMouse

    =
    new AutoMouse ( Point )
  • ExpressionStatement

    :

    dict_keys(['type', 'expression', 'pos'])
  • ExpressionStatement

    :

    dict_keys(['type', 'expression', 'pos'])