2016-07-06 18:54:59 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 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-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkColor.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkPoint.h"
|
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
#include "include/core/SkScalar.h"
|
|
|
|
#include "include/core/SkShader.h"
|
|
|
|
#include "include/core/SkTileMode.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/effects/SkGradientShader.h"
|
2016-07-06 18:54:59 +00:00
|
|
|
|
2019-05-01 21:28:53 +00:00
|
|
|
#include <initializer_list>
|
|
|
|
#include <utility>
|
|
|
|
|
2016-07-06 18:54:59 +00:00
|
|
|
namespace skiagm {
|
|
|
|
|
|
|
|
// Draw stroked rects (both AA and nonAA) with all the types of joins:
|
|
|
|
// bevel, miter, miter-limited-to-bevel, round
|
|
|
|
// and as a hairline.
|
|
|
|
DEF_SIMPLE_GM(stroke_rect_shader, canvas, 690, 300) {
|
2016-09-01 18:24:54 +00:00
|
|
|
constexpr SkRect kRect {0, 0, 100, 100};
|
|
|
|
constexpr SkPoint kPts[] {{kRect.fLeft, kRect.fTop}, {kRect.fRight, kRect.fBottom}};
|
|
|
|
constexpr SkColor kColors[] {SK_ColorRED, SK_ColorBLUE};
|
2016-07-06 18:54:59 +00:00
|
|
|
SkPaint paint;
|
|
|
|
sk_sp<SkShader> shader = SkGradientShader::MakeLinear(kPts, kColors, nullptr, 2,
|
2019-04-03 14:27:45 +00:00
|
|
|
SkTileMode::kClamp);
|
2016-07-06 18:54:59 +00:00
|
|
|
paint.setShader(std::move(shader));
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
// Do a large initial translate so that local coords disagree with device coords significantly
|
|
|
|
// for the first rect drawn.
|
|
|
|
canvas->translate(kRect.centerX(), kRect.centerY());
|
2016-09-01 18:24:54 +00:00
|
|
|
constexpr SkScalar kPad = 20;
|
2016-07-06 18:54:59 +00:00
|
|
|
for (auto aa : {false, true}) {
|
|
|
|
paint.setAntiAlias(aa);
|
|
|
|
canvas->save();
|
|
|
|
|
2016-09-01 18:24:54 +00:00
|
|
|
constexpr SkScalar kStrokeWidth = 10;
|
2016-07-06 18:54:59 +00:00
|
|
|
paint.setStrokeWidth(kStrokeWidth);
|
|
|
|
|
|
|
|
paint.setStrokeJoin(SkPaint::kBevel_Join);
|
|
|
|
canvas->drawRect(kRect, paint);
|
|
|
|
canvas->translate(kRect.width() + kPad, 0);
|
|
|
|
|
|
|
|
paint.setStrokeJoin(SkPaint::kMiter_Join);
|
|
|
|
canvas->drawRect(kRect, paint);
|
|
|
|
canvas->translate(kRect.width() + kPad, 0);
|
|
|
|
|
|
|
|
// This miter limit should effectively produce a bevel join.
|
|
|
|
paint.setStrokeMiter(0.01f);
|
|
|
|
canvas->drawRect(kRect, paint);
|
|
|
|
canvas->translate(kRect.width() + kPad, 0);
|
|
|
|
|
|
|
|
paint.setStrokeJoin(SkPaint::kRound_Join);
|
|
|
|
canvas->drawRect(kRect, paint);
|
|
|
|
canvas->translate(kRect.width() + kPad, 0);
|
|
|
|
|
|
|
|
paint.setStrokeWidth(0);
|
|
|
|
canvas->drawRect(kRect, paint);
|
|
|
|
|
|
|
|
canvas->restore();
|
|
|
|
canvas->translate(0, kRect.height() + kPad);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|