2015-08-19 19:09:12 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 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"
|
|
|
|
#include "include/core/SkCanvas.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkPaint.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkPath.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkScalar.h"
|
|
|
|
#include "include/core/SkSize.h"
|
|
|
|
#include "include/core/SkString.h"
|
2015-08-19 19:09:12 +00:00
|
|
|
|
|
|
|
class ScaledStrokesGM : public skiagm::GM {
|
|
|
|
public:
|
|
|
|
ScaledStrokesGM() {}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
SkString onShortName() override {
|
|
|
|
return SkString("scaledstrokes");
|
|
|
|
}
|
|
|
|
|
|
|
|
SkISize onISize() override {
|
|
|
|
return SkISize::Make(640, 320);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void draw_path(SkScalar size, SkCanvas* canvas, SkPaint paint) {
|
|
|
|
SkScalar c = 0.551915024494f * size;
|
|
|
|
SkPath path;
|
|
|
|
path.moveTo(0.0f, size);
|
|
|
|
path.cubicTo(c, size, size, c, size, 0.0f);
|
|
|
|
path.cubicTo(size, -c, c, -size, 0.0f, -size);
|
|
|
|
path.cubicTo(-c, -size, -size, -c, -size, 0.0f);
|
|
|
|
path.cubicTo(-size, c, -c, size, 0.0f, size);
|
|
|
|
canvas->drawPath(path, paint);
|
|
|
|
}
|
|
|
|
|
|
|
|
void onDraw(SkCanvas* canvas) override {
|
|
|
|
SkPaint paint;
|
|
|
|
SkPath path;
|
|
|
|
paint.setStyle(SkPaint::Style::kStroke_Style);
|
|
|
|
canvas->translate(5.0f, 5.0f);
|
|
|
|
const SkScalar size = 60.0f;
|
|
|
|
for (int i = 0; i < 2; i++) {
|
|
|
|
paint.setAntiAlias(i == 1);
|
|
|
|
for (int j = 0; j < 4; j++) {
|
|
|
|
SkScalar scale = 4.0f - j;
|
|
|
|
paint.setStrokeWidth(4.0f / scale);
|
|
|
|
canvas->save();
|
|
|
|
canvas->translate(size / 2.0f, size / 2.0f);
|
|
|
|
canvas->scale(scale, scale);
|
|
|
|
draw_path(size / 2.0f / scale, canvas, paint);
|
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
canvas->save();
|
|
|
|
canvas->translate(size / 2.0f, 80.0f + size / 2.0f);
|
|
|
|
canvas->scale(scale, scale);
|
|
|
|
canvas->drawCircle(0.0f, 0.0f, size / 2.0f / scale, paint);
|
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
canvas->save();
|
|
|
|
canvas->translate(0.0f, 160.0f);
|
|
|
|
canvas->scale(scale, scale);
|
|
|
|
canvas->drawRect(SkRect::MakeXYWH(0.0f, 0.0f, size / scale, size / scale), paint);
|
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
canvas->save();
|
|
|
|
canvas->translate(0.0f, 240.0f);
|
|
|
|
canvas->scale(scale, scale);
|
|
|
|
canvas->drawLine(0.0f, 0.0f, size / scale, size / scale, paint);
|
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
canvas->translate(80.0f, 0.0f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
DEF_GM( return new ScaledStrokesGM; )
|