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 "include/core/SkCanvas.h"
8 #include "include/core/SkPaint.h"
9 #include "samplecode/Sample.h"
10 
11 class StrokeRectSample : public Sample {
12 public:
StrokeRectSample()13     StrokeRectSample() {}
14 
15 protected:
name()16     virtual SkString name() { return SkString("Stroke Rects"); }
17 
onDrawContent(SkCanvas * canvas)18     virtual void onDrawContent(SkCanvas* canvas) {
19         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     }
57 
58 private:
59     typedef Sample INHERITED;
60 };
61 
62 ///////////////////////////////////////////////////////////////////////////////
63 
64 DEF_SAMPLE( return new StrokeRectSample(); )
65