是否有可能触发由minko中的html事件启动的c ++代码? [英] is it possible to trigger c++ code, initiated by html events in minko?
问题描述
使用 minko (具有"html覆盖"功能),是否可以将事件从html发送到c ++代码? >
所提供的示例以及框架清楚地说明了如何从c ++向html发送事件(通过增加一个计数器并使它反映在html中),是否有可能以另一种方式进行通信?
是.
HTML DOM事件经过包装,可以用作C ++信号.因此,您可以执行以下操作:
dom->getElementById("my-element-id")->onclick()->connect(
[](dom::AbstractDOMMouseEvent::Ptr event)
{
// do something...
}
);
实际上是在同一示例中完成的:Minko.addEventListener("message", yourCallbackFunction)中使用AbstractDOM::onmessage()
收听这些消息.
请注意,您还可以在C ++代码中调用AbstractDOM::eval()
来执行JavaScript代码.这就是我们实际上实现了大多数事情的方式.
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?
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.
这篇关于是否有可能触发由minko中的html事件启动的c ++代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!