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 | ceff287 | 2011-07-27 18:21:37 +0000 | [diff] [blame] | 7 | #include "SampleCode.h" |
| 8 | #include "SkView.h" |
| 9 | #include "SkCanvas.h" |
| 10 | #include "SkCornerPathEffect.h" |
reed@google.com | ceff287 | 2011-07-27 18:21:37 +0000 | [diff] [blame] | 11 | #include "SkGradientShader.h" |
| 12 | #include "SkPath.h" |
| 13 | #include "SkRegion.h" |
| 14 | #include "SkShader.h" |
| 15 | #include "SkUtils.h" |
| 16 | |
| 17 | static void create_bitmap(SkBitmap* bitmap) { |
| 18 | const int W = 100; |
| 19 | const int H = 100; |
commit-bot@chromium.org | a8c1831 | 2014-02-17 02:55:57 +0000 | [diff] [blame] | 20 | bitmap->allocN32Pixels(W, H); |
reed@google.com | ceff287 | 2011-07-27 18:21:37 +0000 | [diff] [blame] | 21 | |
| 22 | SkCanvas canvas(*bitmap); |
| 23 | canvas.drawColor(SK_ColorRED); |
| 24 | SkPaint paint; |
| 25 | paint.setColor(SK_ColorBLUE); |
| 26 | canvas.drawCircle(SkIntToScalar(W)/2, SkIntToScalar(H)/2, SkIntToScalar(W)/2, paint); |
| 27 | } |
| 28 | |
| 29 | class WritePixelsView : public SampleView { |
| 30 | SkPath fPath; |
| 31 | public: |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 32 | WritePixelsView() {} |
| 33 | |
reed@google.com | ceff287 | 2011-07-27 18:21:37 +0000 | [diff] [blame] | 34 | protected: |
| 35 | // overrides from SkEventSink |
| 36 | virtual bool onQuery(SkEvent* evt) { |
| 37 | if (SampleCode::TitleQ(*evt)) { |
| 38 | SampleCode::TitleR(evt, "WritePixels"); |
| 39 | return true; |
| 40 | } |
| 41 | return this->INHERITED::onQuery(evt); |
| 42 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 43 | |
reed@google.com | ceff287 | 2011-07-27 18:21:37 +0000 | [diff] [blame] | 44 | virtual void onDrawContent(SkCanvas* canvas) { |
| 45 | SkBitmap bitmap; |
| 46 | create_bitmap(&bitmap); |
| 47 | int x = bitmap.width() / 2; |
| 48 | int y = bitmap.height() / 2; |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 49 | |
reed@google.com | ceff287 | 2011-07-27 18:21:37 +0000 | [diff] [blame] | 50 | SkBitmap subset; |
| 51 | bitmap.extractSubset(&subset, SkIRect::MakeXYWH(x, y, x, y)); |
| 52 | |
| 53 | canvas->translate(SkIntToScalar(20), SkIntToScalar(20)); |
| 54 | |
| 55 | canvas->writePixels(bitmap, 0, 0); |
| 56 | canvas->writePixels(subset, 0, 0); |
| 57 | } |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 58 | |
reed@google.com | ceff287 | 2011-07-27 18:21:37 +0000 | [diff] [blame] | 59 | private: |
| 60 | typedef SampleView INHERITED; |
| 61 | }; |
| 62 | |
| 63 | ////////////////////////////////////////////////////////////////////////////// |
| 64 | |
| 65 | static SkView* MyFactory() { return new WritePixelsView; } |
| 66 | static SkViewRegister reg(MyFactory); |