我在这里问了一个问题Get mouse screen coordinates on click并得到了一个很好的答案(已确认),感谢 Gaurav Raj
。
在这个示例中:
bool MirrarOrnaments::onMouseDown(FB::MouseDownEvent *evt, FB::PluginWindow *)
{
if(evt->m_Btn == FB::MouseButtonEvent::MouseButton_Left)
{
/**
* apiPtr is the pointer to FB::JSAPIPtr
* mousePositionCallback is the JSAPI function which takes variant list of mouse
* co-ordinates as argument
*/
apiPtr->invoke("mousePositionCallback", FB::variant_list_of(evt->m_x)(evt->m_y));
}
}
据我了解,最后一个字符串必须在我的 JavaScript 中使用 FB::variant_list
参数运行 mousePositionCallback
函数;
但是我无法理解 apiPtr 指针的用途,我在哪里可以得到它以及这个指向 FB::JSAPIPtr
的指针实际上必须如何在我的代码中查找。
最佳答案
FireBreath 中的 FB::JSAPIPtr 类型只是 boost::shared_ptr 的便利别名(共享自动指针,因此您不必在对象上调用 delete,也不必担心它消失)...
尝试添加 getRootJSAPI() 调用,这应该为您返回 apiPtr。
bool MirrarOrnaments::onMouseDown(FB::MouseDownEvent *evt, FB::PluginWindow *)
{
if(evt->m_Btn == FB::MouseButtonEvent::MouseButton_Left)
{
/**
* apiPtr is the pointer to FB::JSAPIPtr
* mousePositionCallback is the JSAPI function which takes variant list of mouse
* co-ordinates as argument
*/
// if you want to access it from the API Part
// FB::JSAPIPtr apiPtr(boost::make_shared<FBYourPluginAPI>(m_plugin));
//add the next line:
FB::JSAPIPtr apiPtr = m_plugin.lock()->getRootJSAPI();
apiPtr->Invoke("mousePositionCallback", FB::variant_list_of(evt->m_x)(evt->m_y));
}
}
关于c++ - Firebreath C++一些指针的理解,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16675509/