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