//--------------------------------------------------------------
void testApp::setup(){
    ofSetWindowShape(WIDTH, HEIGHT);
    
    WebConfig config;
    config.log_path = WSLit(ofToDataPath("Logs").c_str());
    config.log_level = kLogLevel_Verbose; //kLogLevel_Normal;
    
    web_core = WebCore::Initialize(config);
    
    WebPreferences prefs;
    prefs.enable_plugins = true;
    prefs.enable_smooth_scrolling = true;
    
    my_session = web_core->CreateWebSession(WSLit(ofToDataPath("SessionData").c_str()), prefs);
    
    
    web_view = web_core->CreateWebView(WIDTH, HEIGHT, my_session);
    web_view->LoadURL(WebURL(WSLit("http://youtube.com")));
    web_view->Focus();
    //web_view->ExecuteJavascriptWithResult(WSLit("reset()"), WSLit(""));
    
    texture.allocate(WIDTH, HEIGHT, GL_RGBA);
}
void UIUpdateSystem::processEntity(ECS::Entity* entity, float deltaTime)
{
  auto cUI = entity->get<UIComponent>();

  auto webView = cUI->uiWebView;
  auto uiValues = cUI->uiValues;

  if (uiValues->enemy.displayChanged)
  {
    if (uiValues->enemy.display)
    {
      std::string js = "HUD.showHud('enemy');";
      webView->ExecuteJavascript(WSLit(js.c_str()), WSLit(""));
    }
    else
    {
      std::string js = "HUD.hideHud('enemy');";
      webView->ExecuteJavascript(WSLit(js.c_str()), WSLit(""));
    }

    uiValues->enemy.displayChanged = false;
  }
  
  if (uiValues->player.healthChanged)
  {
    std::string js = "HUD.setHP(" + std::to_string(static_cast<int>(1.0f * uiValues->player.currentHealth / uiValues->player.maxHealth * 100)) + ", 'player');";
    webView->ExecuteJavascript(WSLit(js.c_str()), WSLit(""));
    uiValues->player.healthChanged = false;
  }
  else if (uiValues->enemy.display && uiValues->enemy.healthChanged)
  {
    std::string js = "HUD.setHP(" + std::to_string(static_cast<int>(1.0f * uiValues->enemy.currentHealth / uiValues->enemy.maxHealth * 100)) + ", 'enemy');";
    webView->ExecuteJavascript(WSLit(js.c_str()), WSLit(""));
    uiValues->enemy.healthChanged = false;
  }
}
void MenuListener::OnShowPopupMenu(WebView *caller, const WebPopupMenuInfo &menu_info)
{
//	DevMsg("DISABLED FOR TESTING!\n");
//	return;

	//C_WebTab* pWebTab = g_pAnarchyManager->GetWebManager()->GetWebBrowser()->FindWebTab(caller);
	//C_WebTab* pHudWebTab = g_pAnarchyManager->GetWebManager()->GetHudWebTab();
	//WebView* pHudWebView = g_pAnarchyManager->GetWebManager()->GetWebBrowser()->FindWebView(pHudWebTab);

	C_AwesomiumBrowserInstance* pAwesomiumBrowserInstance = g_pAnarchyManager->GetAwesomiumBrowserManager()->FindAwesomiumBrowserInstance(caller);	// FIXME: This should be a general EmbeddedInstance of any type.
	C_AwesomiumBrowserInstance* pHudBrowserInstance = g_pAnarchyManager->GetAwesomiumBrowserManager()->FindAwesomiumBrowserInstance("hud");
	WebView* pHudWebView = pHudBrowserInstance->GetWebView();

	DevMsg("Pop menu detected!\n");

	std::vector<std::string> methodArguments;
	methodArguments.push_back(pAwesomiumBrowserInstance->GetId());
	methodArguments.push_back(VarArgs("%i", menu_info.bounds.x));
	methodArguments.push_back(VarArgs("%i", menu_info.bounds.y));
	methodArguments.push_back(VarArgs("%i", menu_info.bounds.width));
	methodArguments.push_back(VarArgs("%i", menu_info.bounds.height));
	methodArguments.push_back(VarArgs("%i", menu_info.item_height));
	methodArguments.push_back(VarArgs("%f", menu_info.item_font_size));
	methodArguments.push_back(VarArgs("%i", menu_info.selected_item));
	methodArguments.push_back(VarArgs("%i", menu_info.right_aligned));

	for (int i = 0; i < menu_info.items.size(); i++)
	{
		if (menu_info.items[i].type == kWebMenuItemType_Option)
			methodArguments.push_back("Option");
		else if (menu_info.items[i].type == kWebMenuItemType_CheckableOption)
			methodArguments.push_back("CheckableOption");
		else if (menu_info.items[i].type == kWebMenuItemType_Group)
			methodArguments.push_back("Group");
		else if (menu_info.items[i].type == kWebMenuItemType_Separator)
			methodArguments.push_back("Separator");

		methodArguments.push_back(WebStringToCharString(menu_info.items[i].label));
		methodArguments.push_back(WebStringToCharString(menu_info.items[i].tooltip));
		methodArguments.push_back(VarArgs("%i", menu_info.items[i].action));
		methodArguments.push_back(VarArgs("%i", menu_info.items[i].right_to_left));
		methodArguments.push_back(VarArgs("%i", menu_info.items[i].has_directional_override));
		methodArguments.push_back(VarArgs("%i", menu_info.items[i].enabled));
		methodArguments.push_back(VarArgs("%i", menu_info.items[i].checked));
	}
	
	std::string objectName = "window.arcadeHud";
	std::string objectMethod = "showPopupMenu";

	JSValue response = pHudWebView->ExecuteJavascriptWithResult(WSLit(objectName.c_str()), WSLit(""));
	if (response.IsObject())
	{
		JSObject object = response.ToObject();
		JSArray arguments;

		for (auto argument : methodArguments)
			arguments.Push(WSLit(argument.c_str()));

		object.InvokeAsync(WSLit(objectMethod.c_str()), arguments);
	}
}
Esempio n. 4
0
            virtual void ProcessEvent( EFlowEvent evt, SActivationInfo* pActInfo )
            {
                this->awesomium = PluginManager::safeGetPluginConcreteInterface<IPluginAwesomium*>( PLUGIN_NAME );

                if ( awesomium == NULL )
                {
                    return;
                }

                this->sys = this->awesomium->GetSystem();

                switch ( evt )
                {
                    case eFE_Activate:
                        if ( IsPortActive( pActInfo, EIP_START ) )
                        {
                            ActivateOutput<bool>( pActInfo, EOP_STARTED, StartView( GetPortInt( pActInfo, EIP_WIDTH ), GetPortInt( pActInfo, EIP_HEIGHT ), GetPortString( pActInfo, EIP_MATNAME ), GetPortString( pActInfo, EIP_OBJNAME ) ) );
                            std::string url = GetPortString( pActInfo, EIP_TOURL );

                            if ( view && url.length() != 0 )
                            {
                                view->GetView()->LoadURL( WebURL( WSLit( url.c_str() ) ) );
                            }
                        }

                        if ( viewCreated )
                        {
                            if ( IsPortActive( pActInfo, EIP_RELEASE ) )
                            {
                                sys->DeleteView( view );
                                view = NULL;
                                viewCreated = false;
                            }

                            if ( IsPortActive( pActInfo, EIP_TOURL ) )
                            {
                                std::string url = GetPortString( pActInfo, EIP_TOURL );

                                if ( view && url.length() != 0 )
                                {
                                    view->GetView()->LoadURL( WebURL( WSLit( url.c_str() ) ) );
                                }
                            }

                            if ( IsPortActive( pActInfo, EIP_COPY ) )
                            {
                                view->GetView()->Copy();
                            }

                            if ( IsPortActive( pActInfo, EIP_GETLOADING ) )
                            {
                                ActivateOutput<bool>( pActInfo, EOP_LOADING, view->GetView()->IsLoading() );
                            }

                            /*
                            if ( IsPortActive( pActInfo, EIP_GETTITLE ) )
                            {
                                ActivateOutput<string>( pActInfo, EOP_TITLE, view->GetView()->title().data );
                            }

                            if ( IsPortActive( pActInfo, EIP_GETURL ) )
                            {
                                ActivateOutput<string>( pActInfo, EOP_TITLE, view->GetView()->url().path );
                            }
                            */

                            if ( IsPortActive( pActInfo, EIP_GOBACK ) )
                            {
                                view->GetView()->GoBack();
                            }

                            if ( IsPortActive( pActInfo, EIP_GOFORWARD ) )
                            {
                                view->GetView()->GoForward();
                            }

                            if ( IsPortActive( pActInfo, EIP_PASTE ) )
                            {
                                view->GetView()->Paste();
                            }

                            if ( IsPortActive( pActInfo, EIP_REDO ) )
                            {
                                view->GetView()->Redo();
                            }

                            if ( IsPortActive( pActInfo, EIP_REFRESH ) )
                            {
                                view->GetView()->Reload( true );
                            }

                            if ( IsPortActive( pActInfo, EIP_RESIZE ) )
                            {
                                view->GetView()->Resize( GetPortInt( pActInfo, EIP_WIDTH ), GetPortInt( pActInfo, EIP_HEIGHT ) );
                            }

                            if ( IsPortActive( pActInfo, EIP_SELECTALL ) )
                            {
                                view->GetView()->SelectAll();
                            }

                            if ( IsPortActive( pActInfo, EIP_STOP ) )
                            {
                                view->GetView()->Stop();
                            }

                            if ( IsPortActive( pActInfo, EIP_UNDO ) )
                            {
                                view->GetView()->Undo();
                            }
                        }

                        break;
                }
            }