skia2/samplecode/SampleNima.cpp
Ruiqi Mao c5c3df6643 renamed samplecode/Nima to samplecode/SampleNimaActor
Bug: skia:
Change-Id: I305ca837d5ed35df4b519e7283201f0a0f87b1c3
Reviewed-on: https://skia-review.googlesource.com/136636
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Ruiqi Mao <ruiqimao@google.com>
2018-06-22 20:36:17 +00:00

75 lines
1.7 KiB
C++

/*
* Copyright 2018 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SampleCode.h"
#include "SampleNimaActor.h"
#include "SkAnimTimer.h"
#include "SkView.h"
#include <nima/Animation/ActorAnimationInstance.hpp>
#include <cmath>
using namespace nima;
class NimaView : public SampleView {
public:
NimaView()
: fActor(nullptr)
, fAnimation(nullptr) {
}
protected:
// overrides from SkEventSink
virtual bool onQuery(SkEvent* evt) override {
if (SampleCode::TitleQ(*evt)) {
SampleCode::TitleR(evt, "Nima");
return true;
}
return this->INHERITED::onQuery(evt);
}
void onOnceBeforeDraw() override {
// Create the actor.
fActor = std::make_unique<SampleActor>("Robot");
// Get the animation.
fAnimation = fActor->animationInstance("attack");
}
void onDrawContent(SkCanvas* canvas) override {
canvas->save();
canvas->translate(500, 500);
canvas->scale(1, -1);
// Render the actor.
fActor->render(canvas);
canvas->restore();
}
bool onAnimate(const SkAnimTimer& timer) override {
// Apply the animation.
if (fAnimation) {
float time = std::fmod(timer.secs(), fAnimation->max());
fAnimation->time(time);
fAnimation->apply(1.0f);
}
return true;
}
private:
std::unique_ptr<SampleActor> fActor;
ActorAnimationInstance* fAnimation;
typedef SampleView INHERITED;
};
//////////////////////////////////////////////////////////////////////////////
static SkView* MyFactory() { return new NimaView; }
static SkViewRegister reg(MyFactory);