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.
|
|
|
|
*/
|
2009-08-13 19:33:44 +00:00
|
|
|
#include "SampleCode.h"
|
|
|
|
#include "SkView.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkShader.h"
|
|
|
|
#include "SkKey.h"
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void make_paint(SkPaint* paint, SkShader::TileMode tm) {
|
|
|
|
SkBitmap bm;
|
|
|
|
make_bitmap(&bm);
|
|
|
|
|
2016-03-09 02:50:00 +00:00
|
|
|
paint->setShader(SkShader::MakeBitmapShader(bm, tm, tm));
|
2009-08-13 19:33:44 +00:00
|
|
|
}
|
|
|
|
|
2011-06-01 12:42:36 +00:00
|
|
|
class RepeatTileView : public SampleView {
|
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:
|
|
|
|
// overrides from SkEventSink
|
2015-03-26 01:17:31 +00:00
|
|
|
bool onQuery(SkEvent* evt) override {
|
2009-08-13 19:33:44 +00:00
|
|
|
if (SampleCode::TitleQ(*evt)) {
|
|
|
|
SampleCode::TitleR(evt, "RepeatTile");
|
|
|
|
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;
|
|
|
|
make_paint(&paint, SkShader::kRepeat_TileMode);
|
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
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) override {
|
2015-08-27 14:41:13 +00:00
|
|
|
this->inval(nullptr);
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2013-01-08 16:17:50 +00:00
|
|
|
return this->INHERITED::onFindClickHandler(x, y, modi);
|
2009-08-13 19:33:44 +00:00
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
bool onClick(Click* click) override {
|
2009-08-13 19:33:44 +00:00
|
|
|
return this->INHERITED::onClick(click);
|
|
|
|
}
|
|
|
|
|
2013-03-12 14:36:57 +00:00
|
|
|
virtual bool handleKey(SkKey) {
|
2015-08-27 14:41:13 +00:00
|
|
|
this->inval(nullptr);
|
2009-08-13 19:33:44 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2011-06-01 12:42:36 +00:00
|
|
|
typedef SampleView INHERITED;
|
2009-08-13 19:33:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static SkView* MyFactory() { return new RepeatTileView; }
|
|
|
|
static SkViewRegister reg(MyFactory);
|