| 38 | } |
| 39 | |
| 40 | void ImageLayer::onDraw(DrawingContext& drawingContext) { |
| 41 | Layer::onDraw(drawingContext); |
| 42 | |
| 43 | if (_image == nullptr) { |
| 44 | return; |
| 45 | } |
| 46 | |
| 47 | auto drawBounds = drawingContext.drawBounds(); |
| 48 | |
| 49 | auto imageWidth = static_cast<Scalar>(_image->width()); |
| 50 | auto imageHeight = static_cast<Scalar>(_image->height()); |
| 51 | |
| 52 | if (imageWidth == 0 || imageHeight == 0) { |
| 53 | return; |
| 54 | } |
| 55 | |
| 56 | auto imageRect = Rect::makeLTRB(0, 0, imageWidth, imageHeight); |
| 57 | auto imageDrawBounds = drawBounds.makeFittingSize(imageRect.size(), _fittingSizeMode); |
| 58 | |
| 59 | if (_contentScaleX != 1.0) { |
| 60 | auto previousWidth = imageDrawBounds.width(); |
| 61 | auto offsetX = (previousWidth - previousWidth * _contentScaleX) / 2.0; |
| 62 | imageDrawBounds.left += offsetX; |
| 63 | imageDrawBounds.right -= offsetX; |
| 64 | } |
| 65 | |
| 66 | if (_contentScaleY != 1.0) { |
| 67 | auto previousHeight = imageDrawBounds.height(); |
| 68 | auto offsetY = (previousHeight - previousHeight * _contentScaleY) / 2.0; |
| 69 | imageDrawBounds.top += offsetY; |
| 70 | imageDrawBounds.bottom -= offsetY; |
| 71 | } |
| 72 | |
| 73 | auto drawRect = imageDrawBounds.intersection(drawBounds); |
| 74 | |
| 75 | auto drawWidth = imageDrawBounds.width(); |
| 76 | auto drawHeight = imageDrawBounds.height(); |
| 77 | |
| 78 | Scalar matrixScaleX = drawWidth / imageWidth; |
| 79 | Scalar matrixScaleY = drawHeight / imageHeight; |
| 80 | Scalar matrixTranslateX = imageDrawBounds.left; |
| 81 | Scalar matrixTranslateY = imageDrawBounds.top; |
| 82 | |
| 83 | if (_shouldFlip) { |
| 84 | matrixScaleX *= -1.0; |
| 85 | matrixTranslateX += drawWidth; |
| 86 | } |
| 87 | |
| 88 | auto localMatrix = Matrix::makeScaleTranslate(matrixScaleX, matrixScaleY, matrixTranslateX, matrixTranslateY); |
| 89 | |
| 90 | if (_contentRotation != 0.0) { |
| 91 | Scalar centerX = localMatrix.getTranslateX() + drawWidth / 2.0f; |
| 92 | Scalar centerY = localMatrix.getTranslateY() + drawHeight / 2.0f; |
| 93 | localMatrix.postRotate(_contentRotation, centerX, centerY); |
| 94 | } |
| 95 | |
| 96 | auto imagePaint = _imagePaint; |
| 97 |
nothing calls this directly
no test coverage detected