1/*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7#include "include/core/SkBitmap.h"
8#include "include/core/SkCanvas.h"
9#include "include/core/SkShader.h"
10#include "samplecode/Sample.h"
11
12static void make_bitmap(SkBitmap* bm) {
13    const int W = 100;
14    const int H = 100;
15    bm->allocN32Pixels(W, H);
16
17    SkPaint paint;
18    SkCanvas canvas(*bm);
19    canvas.drawColor(SK_ColorWHITE);
20
21    const SkColor colors[] = {
22        SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE
23    };
24
25    for (int ix = 0; ix < W; ix += 1) {
26        SkScalar x = SkIntToScalar(ix) + SK_ScalarHalf;
27        paint.setColor(colors[ix & 3]);
28        canvas.drawLine(x, 0, x, SkIntToScalar(H - 1), paint);
29    }
30    paint.setColor(SK_ColorGRAY);
31    canvas.drawLine(0, 0, SkIntToScalar(W), 0, paint);
32}
33
34static void make_paint(SkPaint* paint, SkTileMode tm) {
35    SkBitmap bm;
36    make_bitmap(&bm);
37
38    paint->setShader(bm.makeShader(tm, tm, SkSamplingOptions()));
39}
40
41class RepeatTileView : public Sample {
42public:
43    RepeatTileView() {
44        this->setBGColor(SK_ColorGRAY);
45    }
46
47protected:
48    SkString name() override { return SkString("RepeatTile"); }
49
50    void onDrawContent(SkCanvas* canvas) override {
51        SkPaint paint;
52        make_paint(&paint, SkTileMode::kRepeat);
53
54//        canvas->scale(SK_Scalar1*2, SK_Scalar1);
55        canvas->translate(SkIntToScalar(100), SkIntToScalar(100));
56        canvas->drawPaint(paint);
57    }
58
59private:
60    using INHERITED = Sample;
61};
62
63//////////////////////////////////////////////////////////////////////////////
64
65DEF_SAMPLE( return new RepeatTileView(); )
66