blob: af3419819152b1f73658aeee76fd38e95fa36def [file] [log] [blame]
reed@android.com8a1c16f2008-12-17 15:59:43 +00001#include "SampleCode.h"
2#include "SkView.h"
3#include "SkCanvas.h"
4#include "SkMovie.h"
5#include "SkTime.h"
6#include <new>
7
8class AnimGifView : public SkView {
9 SkMovie* fMovie;
10public:
11 AnimGifView() {
12 fMovie = SkMovie::DecodeFile("/skimages/dollarblk.gif");
13 }
reed@google.com82065d62011-02-07 15:30:46 +000014
reed@android.com8a1c16f2008-12-17 15:59:43 +000015 virtual ~AnimGifView() {
reed@google.com82065d62011-02-07 15:30:46 +000016 SkSafeUnref(fMovie);
reed@android.com8a1c16f2008-12-17 15:59:43 +000017 }
18
19protected:
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.com82065d62011-02-07 15:30:46 +000028
reed@android.com8a1c16f2008-12-17 15:59:43 +000029 void drawBG(SkCanvas* canvas) {
30 canvas->drawColor(0xFFDDDDDD);
31 }
reed@google.com82065d62011-02-07 15:30:46 +000032
reed@android.com8a1c16f2008-12-17 15:59:43 +000033 virtual void onDraw(SkCanvas* canvas) {
34 this->drawBG(canvas);
reed@google.com82065d62011-02-07 15:30:46 +000035
reed@android.com8a1c16f2008-12-17 15:59:43 +000036 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.com82065d62011-02-07 15:30:46 +000047
reed@android.com8a1c16f2008-12-17 15:59:43 +000048private:
49 SkRect fClip;
50 SkIPoint* fPoints;
51 SkPath fPath;
52 int fPtCount;
53
54 typedef SkView INHERITED;
55};
56
57//////////////////////////////////////////////////////////////////////////////
58
59static SkView* MyFactory() { return new AnimGifView; }
60static SkViewRegister reg(MyFactory);
61