2013-07-09 15:03:59 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 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 "gm/gm.h"
|
2019-04-30 17:44:26 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkColor.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"
|
2013-07-09 15:03:59 +00:00
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
|
2013-07-10 07:00:58 +00:00
|
|
|
// This GM draws a lot of arcs in a 'Z' shape. It particularly exercises
|
2013-07-09 15:03:59 +00:00
|
|
|
// the 'drawArc' code near a singularly of its processing (i.e., near the
|
|
|
|
// edge of one of its underlying quads).
|
|
|
|
class ArcOfZorroGM : public GM {
|
|
|
|
public:
|
|
|
|
ArcOfZorroGM() {
|
2018-08-16 14:17:03 +00:00
|
|
|
this->setBGColor(0xFFCCCCCC);
|
2013-07-09 15:03:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2014-04-30 13:20:45 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkString onShortName() override {
|
2013-07-09 15:03:59 +00:00
|
|
|
return SkString("arcofzorro");
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkISize onISize() override {
|
2014-06-10 06:59:03 +00:00
|
|
|
return SkISize::Make(1000, 1000);
|
2013-07-09 15:03:59 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom rand;
|
2013-07-09 15:03:59 +00:00
|
|
|
|
|
|
|
SkRect rect = SkRect::MakeXYWH(10, 10, 200, 200);
|
|
|
|
|
|
|
|
SkPaint p;
|
|
|
|
|
|
|
|
p.setStyle(SkPaint::kStroke_Style);
|
|
|
|
p.setStrokeWidth(35);
|
|
|
|
int xOffset = 0, yOffset = 0;
|
|
|
|
int direction = 0;
|
|
|
|
|
|
|
|
for (float arc = 134.0f; arc < 136.0f; arc += 0.01f) {
|
|
|
|
SkColor color = rand.nextU();
|
|
|
|
color |= 0xff000000;
|
|
|
|
p.setColor(color);
|
|
|
|
|
|
|
|
canvas->save();
|
|
|
|
canvas->translate(SkIntToScalar(xOffset), SkIntToScalar(yOffset));
|
|
|
|
canvas->drawArc(rect, 0, arc, false, p);
|
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
switch (direction) {
|
|
|
|
case 0:
|
|
|
|
xOffset += 10;
|
|
|
|
if (xOffset >= 700) {
|
|
|
|
direction = 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
xOffset -= 10;
|
|
|
|
yOffset += 10;
|
|
|
|
if (xOffset < 50) {
|
|
|
|
direction = 2;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
xOffset += 10;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-08-26 20:07:48 +00:00
|
|
|
DEF_GM(return new ArcOfZorroGM;)
|
2013-07-09 15:03:59 +00:00
|
|
|
}
|