2011-07-28 14:26:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkBitmap.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkShader.h"
|
|
|
|
#include "samplecode/Sample.h"
|
2009-08-13 19:33:44 +00:00
|
|
|
|
|
|
|
static void make_bitmap(SkBitmap* bm) {
|
|
|
|
const int W = 100;
|
|
|
|
const int H = 100;
|
2014-02-17 02:55:57 +00:00
|
|
|
bm->allocN32Pixels(W, H);
|
2009-08-13 19:33:44 +00:00
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
SkCanvas canvas(*bm);
|
|
|
|
canvas.drawColor(SK_ColorWHITE);
|
|
|
|
|
|
|
|
const SkColor colors[] = {
|
|
|
|
SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE
|
|
|
|
};
|
|
|
|
|
|
|
|
for (int ix = 0; ix < W; ix += 1) {
|
|
|
|
SkScalar x = SkIntToScalar(ix) + SK_ScalarHalf;
|
|
|
|
paint.setColor(colors[ix & 3]);
|
|
|
|
canvas.drawLine(x, 0, x, SkIntToScalar(H - 1), paint);
|
|
|
|
}
|
|
|
|
paint.setColor(SK_ColorGRAY);
|
|
|
|
canvas.drawLine(0, 0, SkIntToScalar(W), 0, paint);
|
|
|
|
}
|
|
|
|
|
2019-04-03 14:27:45 +00:00
|
|
|
static void make_paint(SkPaint* paint, SkTileMode tm) {
|
2009-08-13 19:33:44 +00:00
|
|
|
SkBitmap bm;
|
|
|
|
make_bitmap(&bm);
|
|
|
|
|
2019-04-08 17:20:23 +00:00
|
|
|
paint->setShader(bm.makeShader(tm, tm));
|
2009-08-13 19:33:44 +00:00
|
|
|
}
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
class RepeatTileView : public Sample {
|
2009-08-13 19:33:44 +00:00
|
|
|
public:
|
2012-08-23 18:19:56 +00:00
|
|
|
RepeatTileView() {
|
2011-06-01 12:42:36 +00:00
|
|
|
this->setBGColor(SK_ColorGRAY);
|
|
|
|
}
|
2009-08-13 19:33:44 +00:00
|
|
|
|
|
|
|
protected:
|
2018-08-08 15:36:17 +00:00
|
|
|
bool onQuery(Sample::Event* evt) override {
|
|
|
|
if (Sample::TitleQ(*evt)) {
|
|
|
|
Sample::TitleR(evt, "RepeatTile");
|
2009-08-13 19:33:44 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return this->INHERITED::onQuery(evt);
|
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDrawContent(SkCanvas* canvas) override {
|
2009-08-13 19:33:44 +00:00
|
|
|
SkPaint paint;
|
2019-04-03 14:27:45 +00:00
|
|
|
make_paint(&paint, SkTileMode::kRepeat);
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2009-08-13 19:33:44 +00:00
|
|
|
// canvas->scale(SK_Scalar1*2, SK_Scalar1);
|
|
|
|
canvas->translate(SkIntToScalar(100), SkIntToScalar(100));
|
|
|
|
canvas->drawPaint(paint);
|
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2009-08-13 19:33:44 +00:00
|
|
|
private:
|
2018-08-08 15:36:17 +00:00
|
|
|
typedef Sample INHERITED;
|
2009-08-13 19:33:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
DEF_SAMPLE( return new RepeatTileView(); )
|