blob: 805d5102f157d05e32c01f9d1612f4e642a3e340 [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"
reed@google.comd9097e02011-05-25 20:13:50 +000010#include "SkPaint.h"
11
12class StrokeRectSample : public SampleView {
13public:
14 StrokeRectSample() {}
rmistry@google.comae933ce2012-08-23 18:19:56 +000015
reed@google.comd9097e02011-05-25 20:13:50 +000016protected:
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 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000025
reed@google.comd9097e02011-05-25 20:13:50 +000026 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 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000065
reed@google.comd9097e02011-05-25 20:13:50 +000066private:
67 typedef SampleView INHERITED;
68};
69
70///////////////////////////////////////////////////////////////////////////////
71
72static SkView* MyFactory() { return new StrokeRectSample; }
73static SkViewRegister reg(MyFactory);