#include "SampleCode.h"
#include "SkCanvas.h"
#include "SkDevice.h"
#include "SkPaint.h"
#include "SkRandom.h"
#include "SkShader.h"
#include "SkView.h"
class ManyRectsView : public SampleView {
private:
enum {
N = 1000,
};
public:
ManyRectsView() {}
protected:
virtual bool onQuery(SkEvent* evt) SK_OVERRIDE {
if (SampleCode::TitleQ(*evt)) {
SampleCode::TitleR(evt, "ManyRects");
return true;
}
return this->INHERITED::onQuery(evt);
}
virtual void onDrawContent(SkCanvas* canvas) {
SkISize dsize = canvas->getDeviceSize();
canvas->clear(0xFFF0E0F0);
for (int i = 0; i < N; ++i) {
SkRect rect = SkRect::MakeWH(SkIntToScalar(fRandom.nextRangeU(10, 100)),
SkIntToScalar(fRandom.nextRangeU(10, 100)));
int x = fRandom.nextRangeU(0, dsize.fWidth);
int y = fRandom.nextRangeU(0, dsize.fHeight);
canvas->save();
canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
if (false) {
SkMatrix rotate;
rotate.setRotate(fRandom.nextUScalar1() * 360,
SkIntToScalar(x) + SkScalarHalf(rect.fRight),
SkIntToScalar(y) + SkScalarHalf(rect.fBottom));
canvas->concat(rotate);
}
SkRect clipRect = rect;
clipRect.outset(10, 10);
canvas->clipRect(clipRect);
SkPaint paint;
paint.setColor(fRandom.nextU());
canvas->drawRect(rect, paint);
canvas->restore();
}
this->inval(NULL);
}
private:
SkRandom fRandom;
typedef SampleView INHERITED;
};
static SkView* MyFactory() { return new ManyRectsView; }
static SkViewRegister reg(MyFactory);