paint method

  1. @override
void paint(
  1. PCanvas pCanvas
)
override

The paint operation of this element.

Implementation

@override
void paint(PCanvas pCanvas) {
  var prevState = pCanvas.saveState();

  final prevT = pCanvas.transform;

  final boundingBox = this.boundingBox;
  final boundingBoxTransformed = boundingBox.transform(prevT);

  var t =
      PcanvasTransform(translateX: boundingBox.x, translateY: boundingBox.y);

  try {
    pCanvas.subTransform = t;
    PRectangle? prevClip;
    if (clip) {
      prevClip = pCanvas.clip;
      pCanvas.subClip = boundingBoxTransformed;
    }

    final backgroundColor = this.backgroundColor;
    if (backgroundColor != null && !backgroundColor.isFullyTransparent) {
      // `pCanvas` already translated by `t`.
      pCanvas.fillRect(0, 0, boundingBox.width, boundingBox.height,
          PStyle(color: backgroundColor));
    }

    graphic.paint(pCanvas, GraphicContext.defaultContext);

    if (clip) {
      pCanvas.clip = prevClip;
    }

    final borderColor = this.borderColor;
    if (borderColor != null && borderSize > 0) {
      // `pCanvas` already translated by `t`.
      pCanvas.strokeRect(0, 0, boundingBox.width, boundingBox.height,
          PStyle(color: borderColor, size: borderSize));
    }
  } finally {
    pCanvas.restoreState(expectedState: prevState);
  }
}