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