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 | */ |
Ben Wagner | b2c4ea6 | 2018-08-08 11:36:17 -0400 | [diff] [blame] | 7 | #include "Sample.h" |
reed@google.com | d9097e0 | 2011-05-25 20:13:50 +0000 | [diff] [blame] | 8 | #include "SkCanvas.h" |
reed@google.com | d9097e0 | 2011-05-25 20:13:50 +0000 | [diff] [blame] | 9 | #include "SkPaint.h" |
| 10 | |
Ben Wagner | b2c4ea6 | 2018-08-08 11:36:17 -0400 | [diff] [blame] | 11 | class StrokeRectSample : public Sample { |
reed@google.com | d9097e0 | 2011-05-25 20:13:50 +0000 | [diff] [blame] | 12 | public: |
| 13 | StrokeRectSample() {} |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 14 | |
reed@google.com | d9097e0 | 2011-05-25 20:13:50 +0000 | [diff] [blame] | 15 | protected: |
Ben Wagner | b2c4ea6 | 2018-08-08 11:36:17 -0400 | [diff] [blame] | 16 | virtual bool onQuery(Sample::Event* evt) { |
| 17 | if (Sample::TitleQ(*evt)) { |
| 18 | Sample::TitleR(evt, "Stroke Rects"); |
reed@google.com | d9097e0 | 2011-05-25 20:13:50 +0000 | [diff] [blame] | 19 | return true; |
| 20 | } |
| 21 | return this->INHERITED::onQuery(evt); |
| 22 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 23 | |
reed@google.com | d9097e0 | 2011-05-25 20:13:50 +0000 | [diff] [blame] | 24 | virtual void onDrawContent(SkCanvas* canvas) { |
| 25 | SkPaint paint; |
| 26 | paint.setAntiAlias(true); |
| 27 | paint.setStyle(SkPaint::kStroke_Style); |
| 28 | paint.setStrokeWidth(SkIntToScalar(20)); |
| 29 | |
| 30 | SkPaint hair; |
| 31 | hair.setStyle(SkPaint::kStroke_Style); |
| 32 | hair.setColor(SK_ColorRED); |
| 33 | |
| 34 | static const SkISize gSize[] = { |
| 35 | { 100, 50 }, |
| 36 | { 100, 0 }, |
| 37 | { 0, 50 }, |
| 38 | { 0, 0 } |
| 39 | }; |
| 40 | |
| 41 | static const SkPaint::Join gJoin[] = { |
| 42 | SkPaint::kMiter_Join, |
| 43 | SkPaint::kRound_Join, |
| 44 | SkPaint::kBevel_Join |
| 45 | }; |
| 46 | |
| 47 | canvas->translate(paint.getStrokeWidth(), paint.getStrokeWidth()); |
| 48 | for (size_t i = 0; i < SK_ARRAY_COUNT(gJoin); ++i) { |
| 49 | paint.setStrokeJoin(gJoin[i]); |
| 50 | |
| 51 | canvas->save(); |
| 52 | for (size_t j = 0; j < SK_ARRAY_COUNT(gSize); ++j) { |
| 53 | SkRect r = SkRect::MakeWH(SkIntToScalar(gSize[j].fWidth), |
| 54 | SkIntToScalar(gSize[j].fHeight)); |
| 55 | canvas->drawRect(r, paint); |
| 56 | canvas->drawRect(r, hair); |
| 57 | canvas->translate(0, SkIntToScalar(100)); |
| 58 | } |
| 59 | canvas->restore(); |
| 60 | canvas->translate(SkIntToScalar(150), 0); |
| 61 | } |
| 62 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 63 | |
reed@google.com | d9097e0 | 2011-05-25 20:13:50 +0000 | [diff] [blame] | 64 | private: |
Ben Wagner | b2c4ea6 | 2018-08-08 11:36:17 -0400 | [diff] [blame] | 65 | typedef Sample INHERITED; |
reed@google.com | d9097e0 | 2011-05-25 20:13:50 +0000 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | /////////////////////////////////////////////////////////////////////////////// |
| 69 | |
Ben Wagner | b2c4ea6 | 2018-08-08 11:36:17 -0400 | [diff] [blame] | 70 | DEF_SAMPLE( return new StrokeRectSample(); ) |