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.
|
2011-04-04 14:31:36 +00:00
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkScalar.h"
|
|
|
|
#include "include/core/SkSize.h"
|
|
|
|
#include "include/core/SkString.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/utils/SkRandom.h"
|
2011-04-04 14:31:36 +00:00
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
|
|
|
|
#define W 400
|
|
|
|
#define H 400
|
|
|
|
#define N 100
|
|
|
|
|
2016-09-01 18:24:54 +00:00
|
|
|
constexpr SkScalar SW = SkIntToScalar(W);
|
|
|
|
constexpr SkScalar SH = SkIntToScalar(H);
|
2011-04-04 14:31:36 +00:00
|
|
|
|
2013-12-09 09:14:59 +00:00
|
|
|
class StrokeRectsGM : public GM {
|
2011-04-04 14:31:36 +00:00
|
|
|
public:
|
2013-12-09 09:14:59 +00:00
|
|
|
StrokeRectsGM() {}
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2011-04-04 14:31:36 +00:00
|
|
|
protected:
|
2014-04-30 13:20:45 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkString onShortName() override {
|
2011-04-04 14:31:36 +00:00
|
|
|
return SkString("strokerects");
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkISize onISize() override {
|
2014-06-10 06:59:03 +00:00
|
|
|
return SkISize::Make(W*2, H*2);
|
2011-04-04 14:31:36 +00:00
|
|
|
}
|
|
|
|
|
2014-12-15 20:54:51 +00:00
|
|
|
static void rnd_rect(SkRect* r, SkRandom& rand) {
|
2011-04-04 14:31:36 +00:00
|
|
|
SkScalar x = rand.nextUScalar1() * W;
|
|
|
|
SkScalar y = rand.nextUScalar1() * H;
|
|
|
|
SkScalar w = rand.nextUScalar1() * (W >> 2);
|
|
|
|
SkScalar h = rand.nextUScalar1() * (H >> 2);
|
2011-08-26 14:40:38 +00:00
|
|
|
SkScalar hoffset = rand.nextSScalar1();
|
|
|
|
SkScalar woffset = rand.nextSScalar1();
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2019-08-24 23:39:13 +00:00
|
|
|
r->setXYWH(x, y, w, h);
|
2011-08-26 14:40:38 +00:00
|
|
|
r->offset(-w/2 + woffset, -h/2 + hoffset);
|
2011-04-04 14:31:36 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2011-04-04 14:31:36 +00:00
|
|
|
SkPaint paint;
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
|
|
|
|
for (int y = 0; y < 2; y++) {
|
|
|
|
paint.setAntiAlias(!!y);
|
|
|
|
for (int x = 0; x < 2; x++) {
|
|
|
|
paint.setStrokeWidth(x * SkIntToScalar(3));
|
|
|
|
|
|
|
|
SkAutoCanvasRestore acr(canvas, true);
|
|
|
|
canvas->translate(SW * x, SH * y);
|
2011-05-20 14:05:03 +00:00
|
|
|
canvas->clipRect(SkRect::MakeLTRB(
|
|
|
|
SkIntToScalar(2), SkIntToScalar(2)
|
|
|
|
, SW - SkIntToScalar(2), SH - SkIntToScalar(2)
|
|
|
|
));
|
2011-04-04 14:31:36 +00:00
|
|
|
|
2014-12-15 20:54:51 +00:00
|
|
|
SkRandom rand;
|
2011-04-04 14:31:36 +00:00
|
|
|
for (int i = 0; i < N; i++) {
|
|
|
|
SkRect r;
|
|
|
|
rnd_rect(&r, rand);
|
|
|
|
canvas->drawRect(r, paint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-08-23 18:14:13 +00:00
|
|
|
|
2011-04-04 14:31:36 +00:00
|
|
|
private:
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = GM;
|
2011-04-04 14:31:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2019-01-23 15:22:01 +00:00
|
|
|
DEF_GM( return new StrokeRectsGM; )
|
2011-04-04 14:31:36 +00:00
|
|
|
|
2020-08-06 18:11:56 +00:00
|
|
|
} // namespace skiagm
|