简体   繁体   中英

How can I do a callback from FireBreath to JavaScript

Code sample:

bool MirrarOrnaments::onMouseDown(FB::MouseDownEvent *evt, FB::PluginWindow *) 
{
  if(evt->m_Btn == FB::MouseButtonEvent::MouseButton_Left) 
  {
    //from here i need to function in my JavaScript with argument of FB::variant_list_of(evt->m_x)(evt->m_y)); 
  }
}

Is it possible?
Was trying simply return variant_list to use it in JS,

but it need to be bool anyway cos of:

BEGIN_PLUGIN_EVENT_MAP() 
EVENTTYPE_CASE(FB::MouseDownEvent, onMouseDown, FB::PluginWindow)       
END_PLUGIN_EVENT_MAP()

to have a callback into JavaScript you first need to pass a callback as input to your JSAPI plugins.

you can do this as follows:

in PluginTestAPI.cpp

registerMethod("SetCallback", make_method(this, &PluginTestAPI::SetCallback));

int PluginTestAPI::SetCallback(const FB::JSObjectPtr& callback)
{
  m_CallBack = callback;
}

in PluginTestAPI.h

class PluginTestAPI 
{
  FB::JSObjectPtr* m_pCallback;
  int SetCallback(const FB::JSObjectPtr& callback);

and then in the JavaScript pass this function when you setup:

 function myJSCallback (params)  {
 }

 myplugin.SetCallBack(myJSCallback);

Then you can call this callback from your C++ code:

bool MirrarOrnaments::onMouseDown(FB::MouseDownEvent *evt, FB::PluginWindow *) 
{
  if(evt->m_Btn == FB::MouseButtonEvent::MouseButton_Left) 
  {
    //from here i need to function in my JavaScript with argument of    
    m_pCallback->Invoke(FB::variant_list_of(evt->m_x)(evt->m_y)); 
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM