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 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 14 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 15 | virtual ~AnimGifView() { |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 16 | SkSafeUnref(fMovie); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 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 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 28 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 29 | void drawBG(SkCanvas* canvas) { |
| 30 | canvas->drawColor(0xFFDDDDDD); |
| 31 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 32 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 33 | virtual void onDraw(SkCanvas* canvas) { |
| 34 | this->drawBG(canvas); |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 35 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 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 | } |
reed@google.com | 82065d6 | 2011-02-07 15:30:46 +0000 | [diff] [blame] | 47 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 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 | |