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

Method onDraw

snap_drawing/src/snap_drawing/cpp/Layers/AnimatedImageLayer.cpp:37–59  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35}
36
37void AnimatedImageLayer::onDraw(DrawingContext& drawingContext) {
38 if (_image == nullptr) {
39 return;
40 }
41
42 auto drawBounds = drawingContext.drawBounds();
43
44 auto imageWidth = static_cast<Scalar>(_image->getSize().width);
45 auto imageHeight = static_cast<Scalar>(_image->getSize().height);
46 auto imageRect = Rect::makeLTRB(0, 0, imageWidth, imageHeight);
47
48 auto imageDrawBounds = drawBounds.makeFittingSize(imageRect.size(), _fittingSizeMode);
49
50 // Clip to view bounds. Applied before matrix transform
51 auto drawRect = imageDrawBounds.intersection(drawBounds);
52 drawingContext.clipRect(drawRect);
53
54 if (_shouldFlip) {
55 drawingContext.concat(Matrix::makeScaleTranslate(-1, 1, imageDrawBounds.width(), 0));
56 }
57
58 _image->draw(drawingContext.canvas(), imageDrawBounds, _currentTime, _fittingSizeMode);
59}
60
61void AnimatedImageLayer::onLoadedAssetChanged(const Ref<Valdi::LoadedAsset>& loadedAsset, bool shouldDrawFlipped) {
62 setImage(Valdi::castOrNull<AnimatedImage>(loadedAsset));

Callers

nothing calls this directly

Calls 9

makeFittingSizeMethod · 0.80
canvasMethod · 0.80
drawMethod · 0.65
getSizeMethod · 0.45
sizeMethod · 0.45
intersectionMethod · 0.45
clipRectMethod · 0.45
concatMethod · 0.45
widthMethod · 0.45

Tested by

no test coverage detected