reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1 | #include "SampleCode.h" |
| 2 | #include "SkView.h" |
| 3 | #include "SkCanvas.h" |
| 4 | #include "SkMovie.h" |
| 5 | #include "SkTime.h" |
| 6 | #include <new> |
| 7 | |
| 8 | class AnimGifView : public SkView { |
| 9 | SkMovie* fMovie; |
| 10 | public: |
| 11 | AnimGifView() { |
| 12 | fMovie = SkMovie::DecodeFile("/skimages/dollarblk.gif"); |
| 13 | } |
| 14 | |
| 15 | virtual ~AnimGifView() { |
| 16 | fMovie->safeUnref(); |
| 17 | } |
| 18 | |
| 19 | protected: |
| 20 | // overrides from SkEventSink |
| 21 | virtual bool onQuery(SkEvent* evt) { |
| 22 | if (SampleCode::TitleQ(*evt)) { |
| 23 | SampleCode::TitleR(evt, "Animated Gif"); |
| 24 | return true; |
| 25 | } |
| 26 | return this->INHERITED::onQuery(evt); |
| 27 | } |
| 28 | |
| 29 | void drawBG(SkCanvas* canvas) { |
| 30 | canvas->drawColor(0xFFDDDDDD); |
| 31 | } |
| 32 | |
| 33 | virtual void onDraw(SkCanvas* canvas) { |
| 34 | this->drawBG(canvas); |
| 35 | |
| 36 | if (fMovie) { |
| 37 | if (fMovie->duration()) { |
| 38 | fMovie->setTime(SkTime::GetMSecs() % fMovie->duration()); |
| 39 | } else { |
| 40 | fMovie->setTime(0); |
| 41 | } |
| 42 | canvas->drawBitmap(fMovie->bitmap(), SkIntToScalar(20), |
| 43 | SkIntToScalar(20)); |
| 44 | this->inval(NULL); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | private: |
| 49 | SkRect fClip; |
| 50 | SkIPoint* fPoints; |
| 51 | SkPath fPath; |
| 52 | int fPtCount; |
| 53 | |
| 54 | typedef SkView INHERITED; |
| 55 | }; |
| 56 | |
| 57 | ////////////////////////////////////////////////////////////////////////////// |
| 58 | |
| 59 | static SkView* MyFactory() { return new AnimGifView; } |
| 60 | static SkViewRegister reg(MyFactory); |
| 61 | |