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