2018-06-19 20:05:09 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2018 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
#include "Sample.h"
|
2018-06-21 18:40:28 +00:00
|
|
|
#include "SampleNimaActor.h"
|
2018-06-19 20:05:09 +00:00
|
|
|
#include "SkAnimTimer.h"
|
2018-06-21 15:24:13 +00:00
|
|
|
#include <nima/Animation/ActorAnimationInstance.hpp>
|
2018-06-19 20:05:09 +00:00
|
|
|
#include <cmath>
|
|
|
|
|
|
|
|
using namespace nima;
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
class NimaView : public Sample {
|
2018-06-19 20:05:09 +00:00
|
|
|
public:
|
|
|
|
NimaView()
|
2018-06-21 15:24:13 +00:00
|
|
|
: fActor(nullptr)
|
|
|
|
, fAnimation(nullptr) {
|
2018-06-19 20:05:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2018-08-08 15:36:17 +00:00
|
|
|
virtual bool onQuery(Sample::Event* evt) override {
|
|
|
|
if (Sample::TitleQ(*evt)) {
|
|
|
|
Sample::TitleR(evt, "Nima");
|
2018-06-19 20:05:09 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return this->INHERITED::onQuery(evt);
|
|
|
|
}
|
|
|
|
|
|
|
|
void onOnceBeforeDraw() override {
|
|
|
|
// Create the actor.
|
|
|
|
fActor = std::make_unique<SampleActor>("Robot");
|
|
|
|
|
|
|
|
// Get the animation.
|
2018-06-21 15:24:13 +00:00
|
|
|
fAnimation = fActor->animationInstance("attack");
|
2018-06-19 20:05:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2018-06-21 15:24:13 +00:00
|
|
|
float time = std::fmod(timer.secs(), fAnimation->max());
|
|
|
|
fAnimation->time(time);
|
|
|
|
fAnimation->apply(1.0f);
|
2018-06-19 20:05:09 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::unique_ptr<SampleActor> fActor;
|
2018-06-21 15:24:13 +00:00
|
|
|
ActorAnimationInstance* fAnimation;
|
2018-06-19 20:05:09 +00:00
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
typedef Sample INHERITED;
|
2018-06-19 20:05:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-08-08 15:36:17 +00:00
|
|
|
DEF_SAMPLE( return new NimaView(); )
|