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