Home | History | Annotate | Download | only in samplecode
      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  */
      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:
     18 	AnimGifView() {
     19         fMovie = SkMovie::DecodeFile("/skimages/dollarblk.gif");
     20     }
     21 
     22     virtual ~AnimGifView() {
     23         SkSafeUnref(fMovie);
     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     }
     35 
     36     void drawBG(SkCanvas* canvas) {
     37         canvas->drawColor(0xFFDDDDDD);
     38     }
     39 
     40     virtual void onDraw(SkCanvas* canvas) {
     41         this->drawBG(canvas);
     42 
     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     }
     54 
     55 private:
     56     SkRect      fClip;
     57     SkIPoint*   fPoints;
     58     SkPath      fPath;
     59     int         fPtCount;
     60 
     61     typedef SkView INHERITED;
     62 };
     63 
     64 //////////////////////////////////////////////////////////////////////////////
     65 
     66 static SkView* MyFactory() { return new AnimGifView; }
     67 static SkViewRegister reg(MyFactory);
     68 
     69