diff options
author | reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2009-10-13 13:33:16 +0000 |
---|---|---|
committer | reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2009-10-13 13:33:16 +0000 |
commit | 0f0cfaecf2c52e5fcb033c43df06f07a81c7b0c2 (patch) | |
tree | e353dc169afbde9ab2cef36cb44f7df0d5b7572a /samplecode | |
parent | d0d0e65a6313f01dfd952e8cc214a7c193bec57a (diff) |
check-point for reviving animator
git-svn-id: http://skia.googlecode.com/svn/trunk@380 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'samplecode')
-rw-r--r-- | samplecode/SampleAnimator.cpp | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/samplecode/SampleAnimator.cpp b/samplecode/SampleAnimator.cpp new file mode 100644 index 0000000000..76b1975f92 --- /dev/null +++ b/samplecode/SampleAnimator.cpp @@ -0,0 +1,88 @@ +#include "SampleCode.h" +#include "SkView.h" +#include "SkCanvas.h" + +#include "SkAnimator.h" +#include "SkStream.h" + +class SkAnimatorView : public SkView { +public: + SkAnimatorView(); + virtual ~SkAnimatorView(); + + void setURIBase(const char dir[]); + + SkAnimator* getAnimator() const { return fAnimator; } + + bool decodeFile(const char path[]); + bool decodeMemory(const void* buffer, size_t size); + bool decodeStream(SkStream* stream); + +protected: + // overrides + virtual void onDraw(SkCanvas*); + +private: + SkString fBaseURI; + SkAnimator* fAnimator; + + typedef SkView INHERITED; +}; + +SkAnimatorView::SkAnimatorView() : fAnimator(NULL) { +} + +SkAnimatorView::~SkAnimatorView() { + delete fAnimator; +} + +void SkAnimatorView::setURIBase(const char dir[]) { + fBaseURI.set(dir); +} + +bool SkAnimatorView::decodeFile(const char path[]) { + SkFILEStream* is = new SkFILEStream(path); + SkAutoUnref aur(is); + return is->isValid() && this->decodeStream(is); +} + +bool SkAnimatorView::decodeMemory(const void* buffer, size_t size) { + SkMemoryStream* is = new SkMemoryStream(buffer, size); + SkAutoUnref aur(is); + return this->decodeStream(is); +} + +bool SkAnimatorView::decodeStream(SkStream* stream) { + delete fAnimator; + fAnimator = new SkAnimator; + fAnimator->setURIBase(fBaseURI.c_str()); + if (!fAnimator->decodeStream(stream)) { + delete fAnimator; + fAnimator = NULL; + return false; + } + return true; +} + +#include "SkTime.h" + +void SkAnimatorView::onDraw(SkCanvas* canvas) { + if (fAnimator) { + canvas->drawColor(SK_ColorWHITE); + fAnimator->draw(canvas, SkTime::GetMSecs()); + this->inval(NULL); + } +} + +////////////////////////////////////////////////////////////////////////////// + +static SkView* MyFactory() { + SkAnimatorView* av = new SkAnimatorView; +// av->decodeFile("/skimages/test.xml"); + av->setURIBase("/skia/trunk/animations/"); + av->decodeFile("/skia/trunk/animations/movie#1.xml"); + return av; +} + +static SkViewRegister reg(MyFactory); + |