• Jump To … +
    ./source/core/animationloop.js ./source/core/component.js ./source/core/document.js ./source/core/events.js ./source/core/init.js ./source/core/library.js ./source/core/userInteraction.js ./source/core/utilities.js ./source/factory/action.js ./source/factory/anchor.js ./source/factory/animation.js ./source/factory/bezier.js ./source/factory/block.js ./source/factory/canvas.js ./source/factory/cell.js ./source/factory/cog.js ./source/factory/color.js ./source/factory/coordinate.js ./source/factory/element.js ./source/factory/emitter.js ./source/factory/filter.js ./source/factory/fontAttributes.js ./source/factory/gradient.js ./source/factory/grid.js ./source/factory/group.js ./source/factory/imageAsset.js ./source/factory/line.js ./source/factory/loom.js ./source/factory/mesh.js ./source/factory/net.js ./source/factory/noise.js ./source/factory/oval.js ./source/factory/palette.js ./source/factory/particle.js ./source/factory/particleForce.js ./source/factory/particleHistory.js ./source/factory/particleSpring.js ./source/factory/particleWorld.js ./source/factory/pattern.js ./source/factory/phrase.js ./source/factory/picture.js ./source/factory/polygon.js ./source/factory/polyline.js ./source/factory/quadratic.js ./source/factory/quaternion.js ./source/factory/radialGradient.js ./source/factory/rectangle.js ./source/factory/renderAnimation.js ./source/factory/shape.js ./source/factory/spiral.js ./source/factory/spriteAsset.js ./source/factory/stack.js ./source/factory/star.js ./source/factory/state.js ./source/factory/tetragon.js ./source/factory/ticker.js ./source/factory/tracer.js ./source/factory/tween.js ./source/factory/unstackedElement.js ./source/factory/vector.js ./source/factory/videoAsset.js ./source/factory/wheel.js ./source/mixin/anchor.js ./source/mixin/asset.js ./source/mixin/assetConsumer.js ./source/mixin/base.js ./source/mixin/cascade.js ./source/mixin/delta.js ./source/mixin/displayShape.js ./source/mixin/dom.js ./source/mixin/entity.js ./source/mixin/filter.js ./source/mixin/mimic.js ./source/mixin/path.js ./source/mixin/pattern.js ./source/mixin/pivot.js ./source/mixin/position.js ./source/mixin/shapeBasic.js ./source/mixin/shapeCurve.js ./source/mixin/shapePathCalculation.js ./source/mixin/styles.js ./source/mixin/tween.js ./source/worker/filter-string.js ./source/worker/filter.js
  • ¶

    Block factory

    Block entitys are rectangles rendered onto a DOM <canvas> element using the Canvas API’s Path2D interface - specifically the rect method.

    • Positioning and dimensions functionality for the Block is supplied by the position mixin, while rendering functionality comes from the entity mixin.
    • Blocks can use CSS color Strings for their fillStyle and strokeStyle values, alongside Gradient, RadialGradient, Color and Pattern objects.
    • They will also accept Filter objects.
    • They can use Anchor objects for user navigation.
    • They can be rendered to the canvas by including them in a Cell object’s Group.
    • They can be animated directly, or using delta animation, or act as the target for Tween animations.
    • Blocks can be cloned, and killed.
  • ¶

    Demos:

    • Canvas-001 - Block and Wheel entitys (make, clone, method); drag and drop block and wheel entitys
    • Canvas-005 - Cell-locked, and Entity-locked, gradients; animating gradients by delta, and by tween
    • Canvas-007 - Apply filters at the entity, group and cell level
    • Canvas-009 - Pattern styles; Entity web link anchors; Dynamic accessibility
    • Component-003 - Save and load Scrawl-canvas entity using text packets
  • ¶

    Imports

    import { constructors } from '../core/library.js';
    import { mergeOver } from '../core/utilities.js';
    
    import baseMix from '../mixin/base.js';
    import entityMix from '../mixin/entity.js';
  • ¶

    Block constructor

    const Block = function (items = {}) {
    
        this.entityInit(items);
    
        if (!items.dimensions) {
    
            if (!items.width) this.currentDimensions[0] = this.dimensions[0] = 10;
            if (!items.height) this.currentDimensions[1] = this.dimensions[1] = 10;
        }
    
        return this;
    };
  • ¶

    Block prototype

    let P = Block.prototype = Object.create(Object.prototype);
    P.type = 'Block';
    P.lib = 'entity';
    P.isArtefact = true;
    P.isAsset = false;
  • ¶

    Mixins

    • base
    • entity
    P = baseMix(P);
    P = entityMix(P);
  • ¶

    Block attributes

    • Attributes defined in the base mixin: name.
    • Attributes defined in the position mixin: group, visibility, order, start, startX, startY, handle, handleX, handleY, offset, offsetX, offsetY, dimensions, width, height, pivoted, mimicked, lockTo, lockXTo, lockYTo, scale, roll, noUserInteraction, noPositionDependencies, noCanvasEngineUpdates, noFilters, noPathUpdates, purge, bringToFrontOnDrag.
    • Attributes defined in the delta mixin: delta, noDeltaUpdates.
    • Attributes defined in the pivot mixin: pivot, pivotCorner, addPivotHandle, addPivotOffset, addPivotRotation.
    • Attributes defined in the mimic mixin: mimic, useMimicDimensions, useMimicScale, useMimicStart, useMimicHandle, useMimicOffset, useMimicRotation, useMimicFlip, addOwnDimensionsToMimic, addOwnScaleToMimic, addOwnStartToMimic, addOwnHandleToMimic, addOwnOffsetToMimic, addOwnRotationToMimic.
    • Attributes defined in the path mixin: path, pathPosition, addPathHandle, addPathOffset, addPathRotation, constantPathSpeed.
    • Attributes defined in the entity mixin: method, pathObject, winding, flipReverse, flipUpend, scaleOutline, lockFillStyleToEntity, lockStrokeStyleToEntity, onEnter, onLeave, onDown, onUp, fillStyle, strokeStyle, globalAlpha, globalCompositeOperation, lineWidth, lineCap, lineJoin, lineDash, lineDashOffset, miterLimit, shadowOffsetX, shadowOffsetY, shadowBlur, shadowColor, filter.
    • Attributes defined in the anchor mixin: anchor.
    • Attributes defined in the filter mixin: filters, isStencil.

    No additional attributes required beyond those supplied by the mixins

  • ¶

    Packet management

    No additional packet functionality required

  • ¶

    Clone management

    No additional clone functionality required

  • ¶

    Kill management

    No additional kill functionality required

  • ¶

    Get, Set, deltaSet

    No additional functionality required

  • ¶

    Prototype functions

  • ¶

    cleanPathObject - Calculate the Block entity’s Path2D object

    P.cleanPathObject = function () {
    
        this.dirtyPathObject = false;
    
        if (!this.noPathUpdates || !this.pathObject) {
    
            let p = this.pathObject = new Path2D();
            
            let handle = this.currentStampHandlePosition,
                scale = this.currentScale,
                dims = this.currentDimensions;
    
            let x = -handle[0] * scale,
                y = -handle[1] * scale,
                w = dims[0] * scale,
                h = dims[1] * scale;
    
            p.rect(x, y, w, h);
        }
    };
  • ¶

    Factory

    scrawl.makeBlock({
    
        name: 'myblock-fill',
        width: 100,
        height: 100,
        startX: 25,
        startY: 25,
    
        fillStyle: 'green',
        strokeStyle: 'gold',
    
        lineWidth: 6,
        lineJoin: 'round',
        shadowOffsetX: 4,
        shadowOffsetY: 4,
        shadowBlur: 2,
        shadowColor: 'black',
    
    }).clone({
    
        name: 'myblock-draw',
        startX: 175,
    
        method: 'draw',
        sharedState: true,
    });
    const makeBlock = function (items) {
        return new Block(items);
    };
    
    constructors.Block = Block;
  • ¶

    Exports

    export {
        makeBlock,
    };