particles_bindings.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * Copyright 2019 Google LLC
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #include "include/core/SkCanvas.h"
  8. #include "include/core/SkTypes.h"
  9. #include "include/utils/SkRandom.h"
  10. #include "modules/particles/include/SkParticleAffector.h"
  11. #include "modules/particles/include/SkParticleDrawable.h"
  12. #include "modules/particles/include/SkParticleEffect.h"
  13. #include "modules/particles/include/SkParticleSerialization.h"
  14. #include <string>
  15. #include <emscripten.h>
  16. #include <emscripten/bind.h>
  17. using namespace emscripten;
  18. EMSCRIPTEN_BINDINGS(Particles) {
  19. class_<SkParticleEffect>("SkParticleEffect")
  20. .smart_ptr<sk_sp<SkParticleEffect>>("sk_sp<SkParticleEffect>")
  21. .function("draw", &SkParticleEffect::draw, allow_raw_pointers())
  22. .function("start", select_overload<void (double, bool)>(&SkParticleEffect::start))
  23. .function("update", select_overload<void (double)>(&SkParticleEffect::update));
  24. function("MakeParticles", optional_override([](std::string json)->sk_sp<SkParticleEffect> {
  25. static bool didInit = false;
  26. if (!didInit) {
  27. REGISTER_REFLECTED(SkReflected);
  28. SkParticleAffector::RegisterAffectorTypes();
  29. SkParticleDrawable::RegisterDrawableTypes();
  30. didInit = true;
  31. }
  32. SkRandom r;
  33. sk_sp<SkParticleEffectParams> params(new SkParticleEffectParams());
  34. skjson::DOM dom(json.c_str(), json.length());
  35. SkFromJsonVisitor fromJson(dom.root());
  36. params->visitFields(&fromJson);
  37. return sk_sp<SkParticleEffect>(new SkParticleEffect(std::move(params), r));
  38. }));
  39. constant("particles", true);
  40. }