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 "SampleCode.h"
8#include "SkView.h"
9#include "SkCanvas.h"
10#include "SkPaint.h"
11
12class StrokeRectSample : public SampleView {
13public:
14    StrokeRectSample() {}
15
16protected:
17    // overrides from SkEventSink
18    virtual bool onQuery(SkEvent* evt) {
19        if (SampleCode::TitleQ(*evt)) {
20            SampleCode::TitleR(evt, "Stroke Rects");
21            return true;
22        }
23        return this->INHERITED::onQuery(evt);
24    }
25
26    virtual void onDrawContent(SkCanvas* canvas) {
27        SkPaint paint;
28        paint.setAntiAlias(true);
29        paint.setStyle(SkPaint::kStroke_Style);
30        paint.setStrokeWidth(SkIntToScalar(20));
31
32        SkPaint hair;
33        hair.setStyle(SkPaint::kStroke_Style);
34        hair.setColor(SK_ColorRED);
35
36        static const SkISize gSize[] = {
37            {   100,   50 },
38            {   100,    0 },
39            {     0,   50 },
40            {     0,    0 }
41        };
42
43        static const SkPaint::Join gJoin[] = {
44            SkPaint::kMiter_Join,
45            SkPaint::kRound_Join,
46            SkPaint::kBevel_Join
47        };
48
49        canvas->translate(paint.getStrokeWidth(), paint.getStrokeWidth());
50        for (size_t i = 0; i < SK_ARRAY_COUNT(gJoin); ++i) {
51            paint.setStrokeJoin(gJoin[i]);
52
53            canvas->save();
54            for (size_t j = 0; j < SK_ARRAY_COUNT(gSize); ++j) {
55                SkRect r = SkRect::MakeWH(SkIntToScalar(gSize[j].fWidth),
56                                          SkIntToScalar(gSize[j].fHeight));
57                canvas->drawRect(r, paint);
58                canvas->drawRect(r, hair);
59                canvas->translate(0, SkIntToScalar(100));
60            }
61            canvas->restore();
62            canvas->translate(SkIntToScalar(150), 0);
63        }
64    }
65
66private:
67    typedef SampleView INHERITED;
68};
69
70///////////////////////////////////////////////////////////////////////////////
71
72static SkView* MyFactory() { return new StrokeRectSample; }
73static SkViewRegister reg(MyFactory);
74