blob: 59e0a46cc2032ccd7883f48a8c404720e6fafc23 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
2/*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
reed@google.comd9097e02011-05-25 20:13:50 +00008#include "SampleCode.h"
9#include "SkView.h"
10#include "SkCanvas.h"
11#include "SkDevice.h"
12#include "SkPaint.h"
13
14class StrokeRectSample : public SampleView {
15public:
16 StrokeRectSample() {}
rmistry@google.comae933ce2012-08-23 18:19:56 +000017
reed@google.comd9097e02011-05-25 20:13:50 +000018protected:
19 // overrides from SkEventSink
20 virtual bool onQuery(SkEvent* evt) {
21 if (SampleCode::TitleQ(*evt)) {
22 SampleCode::TitleR(evt, "Stroke Rects");
23 return true;
24 }
25 return this->INHERITED::onQuery(evt);
26 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000027
reed@google.comd9097e02011-05-25 20:13:50 +000028 virtual void onDrawContent(SkCanvas* canvas) {
29 SkPaint paint;
30 paint.setAntiAlias(true);
31 paint.setStyle(SkPaint::kStroke_Style);
32 paint.setStrokeWidth(SkIntToScalar(20));
33
34 SkPaint hair;
35 hair.setStyle(SkPaint::kStroke_Style);
36 hair.setColor(SK_ColorRED);
37
38 static const SkISize gSize[] = {
39 { 100, 50 },
40 { 100, 0 },
41 { 0, 50 },
42 { 0, 0 }
43 };
44
45 static const SkPaint::Join gJoin[] = {
46 SkPaint::kMiter_Join,
47 SkPaint::kRound_Join,
48 SkPaint::kBevel_Join
49 };
50
51 canvas->translate(paint.getStrokeWidth(), paint.getStrokeWidth());
52 for (size_t i = 0; i < SK_ARRAY_COUNT(gJoin); ++i) {
53 paint.setStrokeJoin(gJoin[i]);
54
55 canvas->save();
56 for (size_t j = 0; j < SK_ARRAY_COUNT(gSize); ++j) {
57 SkRect r = SkRect::MakeWH(SkIntToScalar(gSize[j].fWidth),
58 SkIntToScalar(gSize[j].fHeight));
59 canvas->drawRect(r, paint);
60 canvas->drawRect(r, hair);
61 canvas->translate(0, SkIntToScalar(100));
62 }
63 canvas->restore();
64 canvas->translate(SkIntToScalar(150), 0);
65 }
66 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000067
reed@google.comd9097e02011-05-25 20:13:50 +000068private:
69 typedef SampleView INHERITED;
70};
71
72///////////////////////////////////////////////////////////////////////////////
73
74static SkView* MyFactory() { return new StrokeRectSample; }
75static SkViewRegister reg(MyFactory);