blob: d80afe78bb7d46d0a11ec138af7509d6682ed1ae [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 */
Ben Wagnerb2c4ea62018-08-08 11:36:17 -04007#include "Sample.h"
reed@google.comd9097e02011-05-25 20:13:50 +00008#include "SkCanvas.h"
reed@google.comd9097e02011-05-25 20:13:50 +00009#include "SkPaint.h"
10
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:
Ben Wagnerb2c4ea62018-08-08 11:36:17 -040016 virtual bool onQuery(Sample::Event* evt) {
17 if (Sample::TitleQ(*evt)) {
18 Sample::TitleR(evt, "Stroke Rects");
reed@google.comd9097e02011-05-25 20:13:50 +000019 return true;
20 }
21 return this->INHERITED::onQuery(evt);
22 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000023
reed@google.comd9097e02011-05-25 20:13:50 +000024 virtual void onDrawContent(SkCanvas* canvas) {
25 SkPaint paint;
26 paint.setAntiAlias(true);
27 paint.setStyle(SkPaint::kStroke_Style);
28 paint.setStrokeWidth(SkIntToScalar(20));
29
30 SkPaint hair;
31 hair.setStyle(SkPaint::kStroke_Style);
32 hair.setColor(SK_ColorRED);
33
34 static const SkISize gSize[] = {
35 { 100, 50 },
36 { 100, 0 },
37 { 0, 50 },
38 { 0, 0 }
39 };
40
41 static const SkPaint::Join gJoin[] = {
42 SkPaint::kMiter_Join,
43 SkPaint::kRound_Join,
44 SkPaint::kBevel_Join
45 };
46
47 canvas->translate(paint.getStrokeWidth(), paint.getStrokeWidth());
48 for (size_t i = 0; i < SK_ARRAY_COUNT(gJoin); ++i) {
49 paint.setStrokeJoin(gJoin[i]);
50
51 canvas->save();
52 for (size_t j = 0; j < SK_ARRAY_COUNT(gSize); ++j) {
53 SkRect r = SkRect::MakeWH(SkIntToScalar(gSize[j].fWidth),
54 SkIntToScalar(gSize[j].fHeight));
55 canvas->drawRect(r, paint);
56 canvas->drawRect(r, hair);
57 canvas->translate(0, SkIntToScalar(100));
58 }
59 canvas->restore();
60 canvas->translate(SkIntToScalar(150), 0);
61 }
62 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000063
reed@google.comd9097e02011-05-25 20:13:50 +000064private:
Ben Wagnerb2c4ea62018-08-08 11:36:17 -040065 typedef Sample INHERITED;
reed@google.comd9097e02011-05-25 20:13:50 +000066};
67
68///////////////////////////////////////////////////////////////////////////////
69
Ben Wagnerb2c4ea62018-08-08 11:36:17 -040070DEF_SAMPLE( return new StrokeRectSample(); )