An object that can be displayed in a SimView, often it is the visible representation of a SimObject. The SimView determines the simulation coordinates and CoordMap which are used to place the object on the screen.

Each DisplayObject has a default policy about when the SimObject it represents is dragable; this can be overridden via the setDragable method.

Many DisplayObjects allow specifying a prototype DisplayObject. When a display property is undefined, then the property is fetched from the prototype. If it is also undefined on the prototype then a default value is used.

See the View section of myPhysicsLab Architecture for more about how DisplayObjects are used within an application.

interface DisplayObject {
    contains(p_world): boolean;
    draw(context, map): void;
    getChanged(): boolean;
    getMassObjects(): MassObject[];
    getPosition(): Vector;
    getSimObjects(): SimObject[];
    getZIndex(): number;
    isDragable(): boolean;
    setDragable(dragable): void;
    setPosition(position): void;
    setZIndex(zIndex?): void;
    toStringShort(): string;
}

Hierarchy (view full)

Implemented by

Methods

  • Whether the DisplayObject contains the given world coordinates point.

    Parameters

    • p_world: Vector

      the point in world coordinates

    Returns boolean

    true if this DisplayObject contains the given point

  • Draws this DisplayObject using the given CoordMap.

    Parameters

    • context: CanvasRenderingContext2D

      the canvas's context to draw this object into

    • map: CoordMap

      the mapping to use for translating between simulation and screen coordinates

    Returns void

  • Returns true if this DisplayObject has changed, and sets the state to "unchanged".

    Returns boolean

    whether this DisplayObject has changed

  • Returns the set of MassObjects that this DisplayObject represents. Returns an empty list if this DisplayObject doesn't represent a MassObject.

    Returns MassObject[]

    the set of MassObjects that this DisplayObject represents

  • Returns this DisplayObject's position in space, in simulation coordinates of the containing SimView.

    Returns Vector

    this DisplayObject's position, in simulation coordinates.

  • Returns the set of SimObjects that this DisplayObject represents. Returns an empty list if this DisplayObject doesn't represent a SimObject.

    Returns SimObject[]

    the set of SimObjects that this DisplayObject represents

  • Sets the z-index which specifies front-to-back ordering of objects; objects with a higher zIndex are drawn over (in front of) objects with a lower zIndex.

    Returns number

    the zIndex of this DisplayObject

  • Whether this DisplayObject is currently dragable.

    Returns boolean

    true if this DisplayObject is dragable.

  • Sets whether this DisplayObject is currently dragable; has no effect on objects that are not dragable.

    Parameters

    • dragable: boolean

      whether this DisplayObject should be dragable

    Returns void

  • Sets this DisplayObject's position in simulation coordinates of the containing SimView. Each type of DisplayObject has a different policy regarding whether this will have an effect. Generally the policies are:

    • If the DisplayObject does not represent a SimObject, then the position can be set. Examples are DisplayClock, EnergyBarGraph.

    • If the SimObject's position is dependent on other objects, then the position cannot be set. Examples are DisplayConnector, DisplayRope, DisplaySpring.

    • If the SimObject can be moved independently and isDragable is true, then the position of the SimObject is modified. Example: DisplayShape.

    Parameters

    • position: GenericVector

      this DisplayObject's position, in simulation coordinates.

    Returns void

  • Sets the z-index which specifies front-to-back ordering of objects; objects with a higher zIndex are drawn over objects with a lower zIndex. Default is zero.

    Parameters

    • Optional zIndex: number

      the zIndex of this DisplayObject

    Returns void

  • Returns a minimal string representation of this object, usually giving just identity information like the class name and name of the object.

    For an object whose main purpose is to represent another Printable object, it is recommended to include the result of calling toStringShort on that other object. For example, calling toStringShort() on a DisplayShape might return something like this:

    DisplayShape{polygon:Polygon{'chain3'}}
    

    Returns string

    a minimal string representation of this object.

Generated using TypeDoc