htmlc++overlayminko

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


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 events from c++ towards html (by incrementing a counter and having it reflect in html), is it possible to have the communication the other way around?


Solution

  • 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.