blob: 5928f92ae7dd947f08c7e6b1a0d65818886bb6f3 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
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.com8a1c16f2008-12-17 15:59:43 +00008#include "SampleCode.h"
9#include "SkView.h"
10#include "SkCanvas.h"
11#include "SkMovie.h"
12#include "SkTime.h"
13#include <new>
14
15class AnimGifView : public SkView {
16 SkMovie* fMovie;
17public:
rmistry@google.comae933ce2012-08-23 18:19:56 +000018 AnimGifView() {
reed@android.com8a1c16f2008-12-17 15:59:43 +000019 fMovie = SkMovie::DecodeFile("/skimages/dollarblk.gif");
20 }
reed@google.com82065d62011-02-07 15:30:46 +000021
reed@android.com8a1c16f2008-12-17 15:59:43 +000022 virtual ~AnimGifView() {
reed@google.com82065d62011-02-07 15:30:46 +000023 SkSafeUnref(fMovie);
reed@android.com8a1c16f2008-12-17 15:59:43 +000024 }
25
26protected:
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.com82065d62011-02-07 15:30:46 +000035
reed@android.com8a1c16f2008-12-17 15:59:43 +000036 void drawBG(SkCanvas* canvas) {
37 canvas->drawColor(0xFFDDDDDD);
38 }
reed@google.com82065d62011-02-07 15:30:46 +000039
reed@android.com8a1c16f2008-12-17 15:59:43 +000040 virtual void onDraw(SkCanvas* canvas) {
41 this->drawBG(canvas);
reed@google.com82065d62011-02-07 15:30:46 +000042
reed@android.com8a1c16f2008-12-17 15:59:43 +000043 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.com82065d62011-02-07 15:30:46 +000054
reed@android.com8a1c16f2008-12-17 15:59:43 +000055private:
reed@android.com8a1c16f2008-12-17 15:59:43 +000056 SkPath fPath;
reed@android.com8a1c16f2008-12-17 15:59:43 +000057
58 typedef SkView INHERITED;
59};
60
61//////////////////////////////////////////////////////////////////////////////
62
63static SkView* MyFactory() { return new AnimGifView; }
64static SkViewRegister reg(MyFactory);