MCPcopy Create free account
hub / github.com/Snapchat/Valdi / onDraw

Method onDraw

snap_drawing/src/snap_drawing/cpp/Layers/ImageLayer.cpp:40–142  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38}
39
40void 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

Callers

nothing calls this directly

Calls 15

radiusToSigmaFunction · 0.85
makeImageFunction · 0.85
makeFittingSizeMethod · 0.80
getTranslateXMethod · 0.80
getTranslateYMethod · 0.80
postRotateMethod · 0.80
getSkValueMethod · 0.80
isIdentityColorMatrixMethod · 0.80
getColorMatrixMethod · 0.80
getBlurRadiusMethod · 0.80
clipPathMethod · 0.80
drawImageMethod · 0.80

Tested by

no test coverage detected