blob: c12a274b4d2fcd8c191f9b343e50ad4d637a0496 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
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 */
Mike Kleinc0bd9f92019-04-23 12:05:21 -05007#include "include/core/SkBitmap.h"
8#include "include/core/SkCanvas.h"
9#include "include/core/SkShader.h"
10#include "samplecode/Sample.h"
reed@android.comf7d57262009-08-13 19:33:44 +000011
12static void make_bitmap(SkBitmap* bm) {
13 const int W = 100;
14 const int H = 100;
commit-bot@chromium.orga8c18312014-02-17 02:55:57 +000015 bm->allocN32Pixels(W, H);
reed@android.comf7d57262009-08-13 19:33:44 +000016
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
Mike Reedfae8fce2019-04-03 10:27:45 -040034static void make_paint(SkPaint* paint, SkTileMode tm) {
reed@android.comf7d57262009-08-13 19:33:44 +000035 SkBitmap bm;
36 make_bitmap(&bm);
37
Mike Reed50acf8f2019-04-08 13:20:23 -040038 paint->setShader(bm.makeShader(tm, tm));
reed@android.comf7d57262009-08-13 19:33:44 +000039}
40
Ben Wagnerb2c4ea62018-08-08 11:36:17 -040041class RepeatTileView : public Sample {
reed@android.comf7d57262009-08-13 19:33:44 +000042public:
rmistry@google.comae933ce2012-08-23 18:19:56 +000043 RepeatTileView() {
reed@google.com81e3d7f2011-06-01 12:42:36 +000044 this->setBGColor(SK_ColorGRAY);
45 }
reed@android.comf7d57262009-08-13 19:33:44 +000046
47protected:
Hal Canary8a027312019-07-03 10:55:44 -040048 SkString name() override { return SkString("RepeatTile"); }
rmistry@google.comae933ce2012-08-23 18:19:56 +000049
mtklein36352bf2015-03-25 18:17:31 -070050 void onDrawContent(SkCanvas* canvas) override {
reed@android.comf7d57262009-08-13 19:33:44 +000051 SkPaint paint;
Mike Reedfae8fce2019-04-03 10:27:45 -040052 make_paint(&paint, SkTileMode::kRepeat);
rmistry@google.comae933ce2012-08-23 18:19:56 +000053
reed@android.comf7d57262009-08-13 19:33:44 +000054// canvas->scale(SK_Scalar1*2, SK_Scalar1);
55 canvas->translate(SkIntToScalar(100), SkIntToScalar(100));
56 canvas->drawPaint(paint);
57 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000058
reed@android.comf7d57262009-08-13 19:33:44 +000059private:
John Stiles7571f9e2020-09-02 22:42:33 -040060 using INHERITED = Sample;
reed@android.comf7d57262009-08-13 19:33:44 +000061};
62
63//////////////////////////////////////////////////////////////////////////////
64
Ben Wagnerb2c4ea62018-08-08 11:36:17 -040065DEF_SAMPLE( return new RepeatTileView(); )