TextAnimation.cpp revision 260ab726486317496bc12a57d599ea96dcde3284
1/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "TestSceneBase.h"
18#include "utils/Color.h"
19
20class TextAnimation;
21
22static TestScene::Registrar _Text(TestScene::Info{
23    "text",
24    "Draws a bunch of text.",
25    TestScene::simpleCreateScene<TextAnimation>
26});
27
28class TextAnimation : public TestScene {
29public:
30    sp<RenderNode> card;
31    void createContent(int width, int height, Canvas& canvas) override {
32        canvas.drawColor(Color::White, SkBlendMode::kSrcOver);
33        card = TestUtils::createNode(0, 0, width, height,
34                [](RenderProperties& props, Canvas& canvas) {
35            SkPaint paint;
36            paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
37            paint.setAntiAlias(true);
38            paint.setTextSize(50);
39
40            paint.setColor(Color::Black);
41            for (int i = 0; i < 10; i++) {
42                TestUtils::drawUtf8ToCanvas(&canvas, "Test string", paint, 400, i * 100);
43            }
44
45            SkPath path;
46            path.addOval(SkRect::MakeLTRB(100, 100, 300, 300));
47
48            paint.setColor(Color::Blue_500);
49            TestUtils::drawUtf8ToCanvas(&canvas, "This is a neat circle of text!", paint, path);
50        });
51        canvas.drawRenderNode(card.get());
52    }
53
54    void doFrame(int frameNr) override {
55        int curFrame = frameNr % 150;
56        card->mutateStagingProperties().setTranslationX(curFrame);
57        card->mutateStagingProperties().setTranslationY(curFrame);
58        card->setPropertyFieldsDirty(RenderNode::X | RenderNode::Y);
59    }
60};
61