StageXL icon indicating copy to clipboard operation
StageXL copied to clipboard

Consider adding a view of other display objects

Open bp74 opened this issue 11 years ago • 1 comments

With a View class someone could show the same display object twice. A display object can only be added once to the display list, with the View class this limitation would go away.

class DisplayObjectView extends DisplayObject {

  final DisplayObject content;
  final Matrix contentTransformation = new Matrix.fromIdentity();
  final Matrix _tmpMatrix = new Matrix.fromIdentity();
  final Matrix _oldMatrix = new Matrix.fromIdentity();

  DisplayObjectView(this.content);

  @override
  Rectangle<num> get bounds {
    _tmpMatrix.copyFrom(content.transformationMatrix);
    _tmpMatrix.concat(contentTransformation);
    var rectangle = content.boundsTransformed;
    return _tmpMatrix.transformRectangle(rectangle , rectangle);
  }

  @override
  DisplayObject hitTestInput(num localX, num localY) {
    _tmpMatrix.copyFrom(content.transformationMatrix);
    _tmpMatrix.concat(contentTransformation);

    var deltaX = localX - _tmpMatrix.tx;
    var deltaY = localY - _tmpMatrix.ty;
    var childX = (_tmpMatrix.d * deltaX - _tmpMatrix.c * deltaY) / _tmpMatrix.det;
    var childY = (_tmpMatrix.a * deltaY - _tmpMatrix.b * deltaX) / _tmpMatrix.det;

    var mask = content.mask;
    if (mask != null) {
      var maskX = mask.relativeToParent ? localX : childX;
      var maskY = mask.relativeToParent ? localY : childY;
      if (mask.hitTest(maskX, maskY) == false) return null;
    }

    return content.hitTestInput(childX, childY);
  }

  @override
  void render(RenderState renderState) {
    _oldMatrix.copyFrom(renderState.globalMatrix);
    renderState.globalMatrix.prepend(contentTransformation);
    renderState.renderObject(content);
    renderState.globalMatrix.copyFrom(_oldMatrix);
  }
}

bp74 avatar Sep 22 '14 07:09 bp74

TODO: Add parentToLocal and localToParent TODO: Consider removing contentTransformation

bp74 avatar Nov 02 '14 16:11 bp74