1 /*
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  */
7 #include "Sample.h"
8 #include "SkCanvas.h"
9 #include "SkPaint.h"
10 
11 class StrokeRectSample : public Sample {
12 public:
StrokeRectSample()13     StrokeRectSample() {}
14 
15 protected:
onQuery(Sample::Event * evt)16     virtual bool onQuery(Sample::Event* evt) {
17         if (Sample::TitleQ(*evt)) {
18             Sample::TitleR(evt, "Stroke Rects");
19             return true;
20         }
21         return this->INHERITED::onQuery(evt);
22     }
23 
onDrawContent(SkCanvas * canvas)24     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     }
63 
64 private:
65     typedef Sample INHERITED;
66 };
67 
68 ///////////////////////////////////////////////////////////////////////////////
69 
70 DEF_SAMPLE( return new StrokeRectSample(); )
71