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;
|
|
|
|
bm->setConfig(SkBitmap::kARGB_8888_Config, W, H);
|
|
|
|
bm->allocPixels();
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2012-08-23 18:19:56 +00:00
|
|
|
SkShader* shader = SkShader::CreateBitmapShader(bm, tm, tm);
|
2009-08-13 19:33:44 +00:00
|
|
|
paint->setShader(shader)->unref();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
virtual bool onQuery(SkEvent* evt) {
|
|
|
|
if (SampleCode::TitleQ(*evt)) {
|
|
|
|
SampleCode::TitleR(evt, "RepeatTile");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return this->INHERITED::onQuery(evt);
|
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2011-06-01 12:42:36 +00:00
|
|
|
virtual void onDrawContent(SkCanvas* canvas) {
|
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
|
|
|
|
2013-01-08 16:17:50 +00:00
|
|
|
virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) SK_OVERRIDE {
|
2009-08-13 19:33:44 +00:00
|
|
|
this->inval(NULL);
|
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
|
|
|
|
2009-08-13 19:33:44 +00:00
|
|
|
virtual bool onClick(Click* click) {
|
|
|
|
return this->INHERITED::onClick(click);
|
|
|
|
}
|
|
|
|
|
2013-03-12 14:36:57 +00:00
|
|
|
virtual bool handleKey(SkKey) {
|
2009-08-13 19:33:44 +00:00
|
|
|
this->inval(NULL);
|
|
|
|
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);
|