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