is it possible to trigger c++ code, initiated by html events in minko?

后端 未结 1 1129
旧巷少年郎
旧巷少年郎 2020-12-22 07:47

Using minko, \"html overlay\" feature, is it possible to send events to c++ code from html?

The example provided, with the framework clearly demonstrate how to send

相关标签:
1条回答
  • 2020-12-22 08:33

    Yes.

    HTML DOM events are wrapped and made available as C++ signals. So you can do something like:

    dom->getElementById("my-element-id")->onclick()->connect(
      [](dom::AbstractDOMMouseEvent::Ptr event)
      {
        // do something...
      }
    );
    

    It's actually done in the same example: https://github.com/aerys/minko/blob/master/example/html-overlay/src/Main.cpp#L110

    You can also send and receive "messages" both ways using the AbstractDOM::sendMessage() method in C++ or Minko.sendMessage() function in JS. You can listen to those messages using AbstractDOM::onmessage() in C++ and Minko.addEventListener("message", yourCallbackFunction).

    Note that you can also call AbstractDOM::eval() in your C++ code to execute JavaScript code. It's how we've implemented most of the things actually.

    0 讨论(0)
提交回复
热议问题