Class AbstractComponentAbstract

A base class for everything that can be added to an EditorImage.

In addition to the abstract methods, there are a few methods that should be overridden when creating a selectable/erasable subclass:

  • keyPoints: Overriding this may improve how the component interacts with the selection tool.
  • withRegionErased: Override/implement this to allow the component to be partially erased by the partial stroke eraser.

Hierarchy (View Summary)

Constructors

Properties

contentBBox: Rect2

The bounding box of this component. getBBox, by default, returns contentBBox. This must be set by components.

If this changes, EditorImage.queueRerenderOf should be called for this object (provided that this object has been added to the editor.)

Note: This value is ignored if getSizingMode returns FillScreen or FillImage.

lastChangedTime: number

The timestamp (milliseconds) at which the component was last changed (i.e. created/translated).

Methods

  • Parameters

    • localizationTable: ImageComponentLocalization

    Returns string

    a description that could be read by a screen reader (e.g. when adding/erasing the component)

  • Returns number

    an approximation of the proportional time it takes to render this component. This is intended to be a rough estimate, but, for example, a stroke with two points sould have a renderingWeight approximately twice that of a stroke with one point.

  • Parameters

    Returns boolean

    true if this component intersects rect -- it is entirely contained within the rectangle or one of the rectangle's edges intersects this component.

    The default implementation assumes that this.getExactBBox() returns a tight bounding box -- that any horiziontal/vertical line that intersects this' boounding box also intersects a point in this component. If this is not the case, components must override this function.

  • Returns a selection of points within this object. Each contiguous section of this object should have a point in the returned array.

    Subclasses should override this method if the center of the bounding box is not contained within the object.

    Returns Vec3[]

  • Optimization

    Should return true if this component covers the entire visibleRect and would prevent anything below this component from being visible.

    Should return false otherwise.

    Parameters

    Returns boolean

  • Renders this component onto the given canvas.

    If visibleRect is given, it should be the region of canvas that is visible -- rendering anything outside of visibleRect should have no visible effect on the resultant image.

    For optimal performance, implementers should call canvas.startObject and canvas.endObject before and after rendering.

    Parameters

    Returns void

  • Convert the component to an object that can be passed to JSON.stringify.

    Do not rely on the output of this function to take a particular form — this function's output can change form without a major version increase.

    Returns {
        data: string | number | any[] | Record<string, any>;
        id: string;
        loadSaveData: LoadSaveDataTable;
        name: string;
        zIndex: number;
    }

  • Return null iff this object cannot be safely serialized/deserialized.

    Returns null | string | number | any[] | Record<string, any>

  • Optional method: Divides this component into sections roughly along the given path, removing parts that are roughly within shape.

    Notes:

    • A default implementation may be provided for this method in the future. Until then, this method is undefined if unsupported.

    viewport should be provided to determine how newly-added points should be rounded.

    Parameters

    Returns AbstractComponent[]

  • Store the deserialization callback (or lack of it) for [componentKind]. If components are registered multiple times (as may be done in automated tests), the most recent deserialization callback is used.

    Parameters

    Returns void

OpenSource licenses