reed@google.com | 1830c7a | 2012-06-04 12:05:43 +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 | */ |
| 8 | #include "SampleCode.h" |
| 9 | #include "SkDumpCanvas.h" |
| 10 | #include "SkView.h" |
| 11 | #include "SkCanvas.h" |
| 12 | #include "Sk64.h" |
| 13 | #include "SkGradientShader.h" |
| 14 | #include "SkGraphics.h" |
| 15 | #include "SkImageDecoder.h" |
| 16 | #include "SkPath.h" |
| 17 | #include "SkPicture.h" |
| 18 | #include "SkRandom.h" |
| 19 | #include "SkRegion.h" |
| 20 | #include "SkShader.h" |
| 21 | #include "SkUtils.h" |
| 22 | #include "SkColorPriv.h" |
| 23 | #include "SkColorFilter.h" |
| 24 | #include "SkTime.h" |
| 25 | #include "SkTypeface.h" |
| 26 | #include "SkXfermode.h" |
| 27 | |
| 28 | #include "SkStream.h" |
| 29 | #include "SkXMLParser.h" |
| 30 | |
| 31 | class PictFileView : public SampleView { |
| 32 | SkString fFilename; |
| 33 | SkPicture* fPicture; |
| 34 | public: |
| 35 | PictFileView(const char name[] = NULL) : fFilename(name) { |
| 36 | fPicture = NULL; |
| 37 | } |
| 38 | |
| 39 | virtual ~PictFileView() { |
| 40 | SkSafeUnref(fPicture); |
| 41 | } |
| 42 | |
| 43 | protected: |
| 44 | // overrides from SkEventSink |
| 45 | virtual bool onQuery(SkEvent* evt) { |
| 46 | if (SampleCode::TitleQ(*evt)) { |
| 47 | SkString name("P:"); |
| 48 | name.append(fFilename); |
| 49 | SampleCode::TitleR(evt, name.c_str()); |
| 50 | return true; |
| 51 | } |
| 52 | return this->INHERITED::onQuery(evt); |
| 53 | } |
| 54 | |
| 55 | virtual void onDrawContent(SkCanvas* canvas) { |
| 56 | if (NULL == fPicture) { |
| 57 | SkFILEStream stream(fFilename.c_str()); |
| 58 | fPicture = SkNEW_ARGS(SkPicture, (&stream)); |
| 59 | } |
| 60 | canvas->drawPicture(*fPicture); |
| 61 | } |
| 62 | |
| 63 | private: |
| 64 | typedef SampleView INHERITED; |
| 65 | }; |
| 66 | |
| 67 | SampleView* CreateSamplePictFileView(const char filename[]); |
| 68 | SampleView* CreateSamplePictFileView(const char filename[]) { |
| 69 | return new PictFileView(filename); |
| 70 | } |
| 71 | |
| 72 | ////////////////////////////////////////////////////////////////////////////// |
| 73 | |
| 74 | #if 0 |
| 75 | static SkView* MyFactory() { return new PictFileView; } |
| 76 | static SkViewRegister reg(MyFactory); |
| 77 | #endif |
| 78 | |