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