0

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?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Jeux
  • 5
  • 5

1 Answers1

1

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.

  • ok, seems to be working now, as I can get the click coord, in c++, however I have 2 questions : 1-clientX(), pageX(), screenX() seems to be returning same values .. is this expected ? (compiling as linux64) 2-how can i read back the parameter passed from JS in c++ ? I am sending this : `...onclick="Minko.sendMessage('first.test')"...` I want to read back 'first.test' in c++. – Jeux Mar 08 '15 at 21:11
  • I've edited my original answer. IDK about the clientX / pageX things: web browsers give me a headache everytime I read the docs about those values. But AFAIK it's to be expected indeed. – Jean-Marc Le Roux Mar 09 '15 at 07:41
  • Your updated answer was what I was looking for, and it worked perfectly for my case. Many thanks ! As for clientX, pageX thing, it is not a big issue for me now, but will update you in case I find a weird behaviour in some browser. – Jeux Mar 09 '15 at 22:19