blob: d4cc4ae119164e77cd4a4ac2936dd9f71ea878c0 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
Mike Kleinc0bd9f92019-04-23 12:05:21 -05007#include "include/core/SkCanvas.h"
8#include "include/core/SkPaint.h"
9#include "samplecode/Sample.h"
reed@google.comd9097e02011-05-25 20:13:50 +000010
Ben Wagnerb2c4ea62018-08-08 11:36:17 -040011class StrokeRectSample : public Sample {
reed@google.comd9097e02011-05-25 20:13:50 +000012public:
13 StrokeRectSample() {}
rmistry@google.comae933ce2012-08-23 18:19:56 +000014
reed@google.comd9097e02011-05-25 20:13:50 +000015protected:
Brian Salomond0072812020-07-21 17:03:56 -040016 SkString name() override { return SkString("Stroke Rects"); }
rmistry@google.comae933ce2012-08-23 18:19:56 +000017
Brian Salomond0072812020-07-21 17:03:56 -040018 void onDrawContent(SkCanvas* canvas) override {
reed@google.comd9097e02011-05-25 20:13:50 +000019 SkPaint paint;
20 paint.setAntiAlias(true);
21 paint.setStyle(SkPaint::kStroke_Style);
22 paint.setStrokeWidth(SkIntToScalar(20));
23
24 SkPaint hair;
25 hair.setStyle(SkPaint::kStroke_Style);
26 hair.setColor(SK_ColorRED);
27
28 static const SkISize gSize[] = {
29 { 100, 50 },
30 { 100, 0 },
31 { 0, 50 },
32 { 0, 0 }
33 };
34
35 static const SkPaint::Join gJoin[] = {
36 SkPaint::kMiter_Join,
37 SkPaint::kRound_Join,
38 SkPaint::kBevel_Join
39 };
40
41 canvas->translate(paint.getStrokeWidth(), paint.getStrokeWidth());
42 for (size_t i = 0; i < SK_ARRAY_COUNT(gJoin); ++i) {
43 paint.setStrokeJoin(gJoin[i]);
44
45 canvas->save();
46 for (size_t j = 0; j < SK_ARRAY_COUNT(gSize); ++j) {
47 SkRect r = SkRect::MakeWH(SkIntToScalar(gSize[j].fWidth),
48 SkIntToScalar(gSize[j].fHeight));
49 canvas->drawRect(r, paint);
50 canvas->drawRect(r, hair);
51 canvas->translate(0, SkIntToScalar(100));
52 }
53 canvas->restore();
54 canvas->translate(SkIntToScalar(150), 0);
55 }
56 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000057
reed@google.comd9097e02011-05-25 20:13:50 +000058private:
John Stiles7571f9e2020-09-02 22:42:33 -040059 using INHERITED = Sample;
reed@google.comd9097e02011-05-25 20:13:50 +000060};
61
62///////////////////////////////////////////////////////////////////////////////
63
Ben Wagnerb2c4ea62018-08-08 11:36:17 -040064DEF_SAMPLE( return new StrokeRectSample(); )