blob: ed1a844ced504abb234716e2b1fb8d3222216c91 [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 }
14
15 virtual ~AnimGifView() {
16 fMovie->safeUnref();
17 }
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 }
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
48private:
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