/* * Copyright 2020 Google LLC * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ #include #include #include "include/core/SkCanvas.h" #include "include/core/SkSurface.h" #include "tools/skui/InputState.h" #include "tools/skui/ModifierKey.h" #include "tools/viewer/SKPSlide.h" #include "tools/viewer/SampleSlide.h" #include "tools/viewer/SvgSlide.h" #include #include using namespace emscripten; static sk_sp MakeSlide(std::string name) { if (name == "PathText") { extern Sample* MakePathTextSample(); return sk_make_sp(MakePathTextSample); } if (name == "TessellatedWedge") { extern Sample* MakeTessellatedWedgeSample(); return sk_make_sp(MakeTessellatedWedgeSample); } return nullptr; } static sk_sp MakeSkpSlide(std::string name, std::string skpData) { auto stream = std::make_unique(skpData.data(), skpData.size(), /*copyData=*/true); return sk_make_sp(SkString(name.c_str()), std::move(stream)); } static sk_sp MakeSvgSlide(std::string name, std::string svgText) { auto stream = std::make_unique(svgText.data(), svgText.size(), /*copyData=*/true); return sk_make_sp(SkString(name.c_str()), std::move(stream)); } EMSCRIPTEN_BINDINGS(Viewer) { function("MakeSlide", &MakeSlide); function("MakeSkpSlide", &MakeSkpSlide); function("MakeSvgSlide", &MakeSvgSlide); class_("Slide") .smart_ptr>("sk_sp") .function("load", &Slide::load) .function("animate", &Slide::animate) .function("draw", optional_override([](Slide& self, SkCanvas& canvas) { self.draw(&canvas); })) .function("onChar", &Slide::onChar) .function("onMouse", &Slide::onMouse); enum_("InputState") .value("Down", skui::InputState::kDown) .value("Up", skui::InputState::kUp) .value("Move", skui::InputState::kMove) .value("Right", skui::InputState::kRight) .value("Left", skui::InputState::kLeft); enum_("ModifierKey") .value("None", skui::ModifierKey::kNone) .value("Shift", skui::ModifierKey::kShift) .value("Control", skui::ModifierKey::kControl) .value("Option", skui::ModifierKey::kOption) .value("Command", skui::ModifierKey::kCommand) .value("FirstPress", skui::ModifierKey::kFirstPress); }