aboutsummaryrefslogtreecommitdiffstats
path: root/samplecode/SampleLCD.cpp
blob: f209e9708941286aba18516b6a58eacee9df7f22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
 * Copyright 2011 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */
#include <SkFont.h>
#include "Sample.h"
#include "SkCanvas.h"
#include "SkPaint.h"
#include "SkShader.h"

class LCDView : public Sample {
public:
    LCDView() {}

protected:
    bool onQuery(Sample::Event* evt) override {
        if (Sample::TitleQ(*evt)) {
            Sample::TitleR(evt, "LCD Text");
            return true;
        }
        return this->INHERITED::onQuery(evt);
    }

    void drawBG(SkCanvas* canvas) {
        canvas->drawColor(SK_ColorWHITE);
    }

    void onDrawContent(SkCanvas* canvas) override {
        this->drawBG(canvas);

        SkPaint paint;

        SkScalar textSize = SkIntToScalar(6);
        SkScalar delta = SK_Scalar1;
        const char* text = "HHHamburgefonts iii";
        size_t len = strlen(text);
        SkScalar x0 = SkIntToScalar(10);
        SkScalar x1 = SkIntToScalar(310);
        SkScalar y = SkIntToScalar(20);

        SkFont font;
        for (int i = 0; i < 20; i++) {
            font.setSize(textSize);
            textSize += delta;

            font.setEdging(SkFont::Edging::kAntiAlias);
            canvas->drawSimpleText(text, len, kUTF8_SkTextEncoding, x0, y, font, paint);
            font.setEdging(SkFont::Edging::kSubpixelAntiAlias);
            canvas->drawSimpleText(text, len, kUTF8_SkTextEncoding, x1, y, font, paint);

            y += font.getSpacing();
        }
    }

private:
    typedef Sample INHERITED;
};

//////////////////////////////////////////////////////////////////////////////

DEF_SAMPLE( return new LCDView(); )