epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 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 | */ |
reed@google.com | d9097e0 | 2011-05-25 20:13:50 +0000 | [diff] [blame] | 7 | #include "SampleCode.h" |
| 8 | #include "SkView.h" |
| 9 | #include "SkCanvas.h" |
reed@google.com | d9097e0 | 2011-05-25 20:13:50 +0000 | [diff] [blame] | 10 | #include "SkPaint.h" |
| 11 | |
| 12 | class StrokeRectSample : public SampleView { |
| 13 | public: |
| 14 | StrokeRectSample() {} |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 15 | |
reed@google.com | d9097e0 | 2011-05-25 20:13:50 +0000 | [diff] [blame] | 16 | protected: |
| 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.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 25 | |
reed@google.com | d9097e0 | 2011-05-25 20:13:50 +0000 | [diff] [blame] | 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 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 65 | |
reed@google.com | d9097e0 | 2011-05-25 20:13:50 +0000 | [diff] [blame] | 66 | private: |
| 67 | typedef SampleView INHERITED; |
| 68 | }; |
| 69 | |
| 70 | /////////////////////////////////////////////////////////////////////////////// |
| 71 | |
| 72 | static SkView* MyFactory() { return new StrokeRectSample; } |
| 73 | static SkViewRegister reg(MyFactory); |