mirror of https://github.com/axmolengine/axmol.git
Windows Phone 8 can now open URLs.
This commit is contained in:
parent
a9a0ff35f6
commit
6e91c65e74
|
@ -54,7 +54,8 @@ Application * Application::sm_pSharedApplication = 0;
|
|||
// sharedApplication pointer
|
||||
Application * s_pSharedApplication = 0;
|
||||
|
||||
Application::Application()
|
||||
Application::Application() :
|
||||
m_openURLDelegate(nullptr)
|
||||
{
|
||||
m_nAnimationInterval.QuadPart = 0;
|
||||
CC_ASSERT(! sm_pSharedApplication);
|
||||
|
@ -179,8 +180,15 @@ Application::Platform Application::getTargetPlatform()
|
|||
|
||||
bool Application::openURL(const std::string &url)
|
||||
{
|
||||
//TODO release this method
|
||||
return false;
|
||||
if (m_openURLDelegate)
|
||||
{
|
||||
m_openURLDelegate(PlatformStringFromString(url));
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void Application::setResourceRootPath(const std::string& rootResDir)
|
||||
|
|
|
@ -31,6 +31,7 @@ THE SOFTWARE.
|
|||
#include "platform/CCStdC.h"
|
||||
#include "platform/CCCommon.h"
|
||||
#include "platform/CCApplicationProtocol.h"
|
||||
#include "platform/winrt/InputEvent.h"
|
||||
#include <string>
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
@ -70,6 +71,15 @@ public:
|
|||
*/
|
||||
virtual bool openURL(const std::string &url);
|
||||
|
||||
/**
|
||||
@brief Set the callback responsible for opening a URL.
|
||||
@param del The delegate that will handle opening a URL. We can't pass back a Platform::String due to name clash.
|
||||
*/
|
||||
void SetXamlOpenURLDelegate(const std::function<void(::Platform::String^)>& del)
|
||||
{
|
||||
m_openURLDelegate = del;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Resource root path.
|
||||
* @deprecated Please use CCFileUtils::sharedFileUtils()->setSearchPaths() instead.
|
||||
|
@ -94,6 +104,8 @@ protected:
|
|||
std::string m_resourceRootPath;
|
||||
std::string m_startupScriptFilename;
|
||||
|
||||
std::function<void(::Platform::String^)> m_openURLDelegate;
|
||||
|
||||
static Application * sm_pSharedApplication;
|
||||
};
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ namespace PhoneDirect3DXamlAppComponent
|
|||
public delegate void Cocos2dEventDelegate(Cocos2dEvent event);
|
||||
public delegate void Cocos2dMessageBoxDelegate(Platform::String^ title, Platform::String^ text);
|
||||
public delegate void Cocos2dEditBoxDelegate(Platform::String^ strPlaceHolder, Platform::String^ strText, int maxLength, int inputMode, int inputFlag, Windows::Foundation::EventHandler<Platform::String^>^ receiveHandler);
|
||||
public delegate void Cocos2dOpenURLDelegate(Platform::String^ url);
|
||||
}
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
|
|
@ -181,7 +181,12 @@ void Cocos2dRenderer::SetXamlEditBoxDelegate(PhoneDirect3DXamlAppComponent::Coco
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void Cocos2dRenderer::SetXamlOpenURLDelegate(PhoneDirect3DXamlAppComponent::Cocos2dOpenURLDelegate^ delegate)
|
||||
{
|
||||
m_openURLDelegate = delegate;
|
||||
Application* app = Application::getInstance();
|
||||
if (app)
|
||||
{
|
||||
app->SetXamlOpenURLDelegate(delegate);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,6 +45,7 @@ public:
|
|||
void SetXamlEventDelegate(PhoneDirect3DXamlAppComponent::Cocos2dEventDelegate^ delegate);
|
||||
void SetXamlMessageBoxDelegate(PhoneDirect3DXamlAppComponent::Cocos2dMessageBoxDelegate^ delegate);
|
||||
void SetXamlEditBoxDelegate(PhoneDirect3DXamlAppComponent::Cocos2dEditBoxDelegate^ delegate);
|
||||
void SetXamlOpenURLDelegate(PhoneDirect3DXamlAppComponent::Cocos2dOpenURLDelegate^ delegate);
|
||||
|
||||
Windows::Foundation::IAsyncAction^ OnSuspending();
|
||||
void Connect();
|
||||
|
@ -61,6 +62,7 @@ private:
|
|||
PhoneDirect3DXamlAppComponent::Cocos2dEventDelegate^ m_delegate;
|
||||
PhoneDirect3DXamlAppComponent::Cocos2dMessageBoxDelegate^ m_messageBoxDelegate;
|
||||
PhoneDirect3DXamlAppComponent::Cocos2dEditBoxDelegate^ m_editBoxDelegate;
|
||||
PhoneDirect3DXamlAppComponent::Cocos2dOpenURLDelegate^ m_openURLDelegate;
|
||||
|
||||
// The AppDelegate for the Cocos2D app
|
||||
AppDelegate* mApp;
|
||||
|
|
|
@ -129,6 +129,11 @@ void Direct3DInterop::OnCocos2dEditboxEvent(Object^ sender, Platform::String^ ar
|
|||
cocos2d::GLViewImpl::sharedOpenGLView()->QueueEvent(e);
|
||||
}
|
||||
|
||||
void Direct3DInterop::OnCocos2dOpenURL(Platform::String^ url)
|
||||
{
|
||||
m_openURLDelegate->Invoke(url);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -174,6 +179,12 @@ void Direct3DInterop::SetCocos2dEditBoxDelegate(Cocos2dEditBoxDelegate ^ delegat
|
|||
m_renderer->SetXamlEditBoxDelegate(delegate);
|
||||
}
|
||||
|
||||
void Direct3DInterop::SetCocos2dOpenURLDelegate(Cocos2dOpenURLDelegate ^ delegate)
|
||||
{
|
||||
m_openURLDelegate = delegate;
|
||||
m_renderer->SetXamlOpenURLDelegate(delegate);
|
||||
}
|
||||
|
||||
|
||||
bool Direct3DInterop::SendCocos2dEvent(Cocos2dEvent event)
|
||||
{
|
||||
|
|
|
@ -60,6 +60,7 @@ public:
|
|||
void OnCocos2dKeyEvent(Cocos2dKeyEvent key);
|
||||
void OnCocos2dKeyEvent(Cocos2dKeyEvent key, Platform::String^ text);
|
||||
void OnCocos2dEditboxEvent(Platform::Object^ sender, Platform::String^ args, Windows::Foundation::EventHandler<Platform::String^>^ handler);
|
||||
void OnCocos2dOpenURL(Platform::String^ url);
|
||||
|
||||
property Windows::Graphics::Display::DisplayOrientations WindowOrientation;
|
||||
property Windows::Foundation::Size WindowBounds;
|
||||
|
@ -67,6 +68,7 @@ public:
|
|||
void SetCocos2dEventDelegate(Cocos2dEventDelegate^ delegate);
|
||||
void SetCocos2dMessageBoxDelegate(Cocos2dMessageBoxDelegate ^ delegate);
|
||||
void SetCocos2dEditBoxDelegate(Cocos2dEditBoxDelegate ^ delegate);
|
||||
void SetCocos2dOpenURLDelegate(Cocos2dOpenURLDelegate ^ delegate);
|
||||
|
||||
|
||||
protected:
|
||||
|
@ -90,6 +92,7 @@ private:
|
|||
Cocos2dEventDelegate^ m_delegate;
|
||||
Cocos2dMessageBoxDelegate^ m_messageBoxDelegate;
|
||||
Cocos2dEditBoxDelegate^ m_editBoxDelegate;
|
||||
Cocos2dOpenURLDelegate^ m_openURLDelegate;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ using Windows.UI.Input;
|
|||
using System.Windows.Threading;
|
||||
using Microsoft.Phone.Info;
|
||||
using Windows.Graphics.Display;
|
||||
using Microsoft.Phone.Tasks;
|
||||
|
||||
namespace PhoneDirect3DXamlAppInterop
|
||||
{
|
||||
|
@ -93,6 +94,7 @@ namespace PhoneDirect3DXamlAppInterop
|
|||
m_d3dInterop.SetCocos2dEventDelegate(OnCocos2dEvent);
|
||||
m_d3dInterop.SetCocos2dMessageBoxDelegate(OnCocos2dMessageBoxEvent);
|
||||
m_d3dInterop.SetCocos2dEditBoxDelegate(OpenEditBox);
|
||||
m_d3dInterop.SetCocos2dOpenURLDelegate(OpenURL);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -199,6 +201,13 @@ namespace PhoneDirect3DXamlAppInterop
|
|||
}
|
||||
}
|
||||
|
||||
public void OpenURL(String url)
|
||||
{
|
||||
WebBrowserTask webBrowserTask = new WebBrowserTask();
|
||||
webBrowserTask.Uri = new Uri(url, UriKind.Absolute);
|
||||
webBrowserTask.Show();
|
||||
}
|
||||
|
||||
private void StartTimer()
|
||||
{
|
||||
m_timer = new DispatcherTimer();
|
||||
|
|
|
@ -25,6 +25,7 @@ using Windows.UI.Input;
|
|||
using System.Windows.Threading;
|
||||
using Microsoft.Phone.Info;
|
||||
using Windows.Graphics.Display;
|
||||
using Microsoft.Phone.Tasks;
|
||||
|
||||
namespace PhoneDirect3DXamlAppInterop
|
||||
{
|
||||
|
@ -93,6 +94,7 @@ namespace PhoneDirect3DXamlAppInterop
|
|||
m_d3dInterop.SetCocos2dEventDelegate(OnCocos2dEvent);
|
||||
m_d3dInterop.SetCocos2dMessageBoxDelegate(OnCocos2dMessageBoxEvent);
|
||||
m_d3dInterop.SetCocos2dEditBoxDelegate(OpenEditBox);
|
||||
m_d3dInterop.SetCocos2dOpenURLDelegate(OpenURL);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -199,6 +201,13 @@ namespace PhoneDirect3DXamlAppInterop
|
|||
}
|
||||
}
|
||||
|
||||
public void OpenURL(String url)
|
||||
{
|
||||
WebBrowserTask webBrowserTask = new WebBrowserTask();
|
||||
webBrowserTask.Uri = new Uri(url, UriKind.Absolute);
|
||||
webBrowserTask.Show();
|
||||
}
|
||||
|
||||
private void StartTimer()
|
||||
{
|
||||
m_timer = new DispatcherTimer();
|
||||
|
|
|
@ -181,7 +181,12 @@ void Cocos2dRenderer::SetXamlEditBoxDelegate(PhoneDirect3DXamlAppComponent::Coco
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void Cocos2dRenderer::SetXamlOpenURLDelegate(PhoneDirect3DXamlAppComponent::Cocos2dOpenURLDelegate^ delegate)
|
||||
{
|
||||
m_openURLDelegate = delegate;
|
||||
Application* app = Application::getInstance();
|
||||
if (app)
|
||||
{
|
||||
app->SetXamlOpenURLDelegate(delegate);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,6 +45,7 @@ public:
|
|||
void SetXamlEventDelegate(PhoneDirect3DXamlAppComponent::Cocos2dEventDelegate^ delegate);
|
||||
void SetXamlMessageBoxDelegate(PhoneDirect3DXamlAppComponent::Cocos2dMessageBoxDelegate^ delegate);
|
||||
void SetXamlEditBoxDelegate(PhoneDirect3DXamlAppComponent::Cocos2dEditBoxDelegate^ delegate);
|
||||
void SetXamlOpenURLDelegate(PhoneDirect3DXamlAppComponent::Cocos2dOpenURLDelegate^ delegate);
|
||||
|
||||
Windows::Foundation::IAsyncAction^ OnSuspending();
|
||||
void Connect();
|
||||
|
@ -61,6 +62,7 @@ private:
|
|||
PhoneDirect3DXamlAppComponent::Cocos2dEventDelegate^ m_delegate;
|
||||
PhoneDirect3DXamlAppComponent::Cocos2dMessageBoxDelegate^ m_messageBoxDelegate;
|
||||
PhoneDirect3DXamlAppComponent::Cocos2dEditBoxDelegate^ m_editBoxDelegate;
|
||||
PhoneDirect3DXamlAppComponent::Cocos2dOpenURLDelegate^ m_openURLDelegate;
|
||||
|
||||
// The AppDelegate for the Cocos2D app
|
||||
AppDelegate* mApp;
|
||||
|
|
|
@ -129,6 +129,11 @@ void Direct3DInterop::OnCocos2dEditboxEvent(Object^ sender, Platform::String^ ar
|
|||
cocos2d::GLViewImpl::sharedOpenGLView()->QueueEvent(e);
|
||||
}
|
||||
|
||||
void Direct3DInterop::OnCocos2dOpenURL(Platform::String^ url)
|
||||
{
|
||||
m_openURLDelegate->Invoke(url);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -174,6 +179,12 @@ void Direct3DInterop::SetCocos2dEditBoxDelegate(Cocos2dEditBoxDelegate ^ delegat
|
|||
m_renderer->SetXamlEditBoxDelegate(delegate);
|
||||
}
|
||||
|
||||
void Direct3DInterop::SetCocos2dOpenURLDelegate(Cocos2dOpenURLDelegate ^ delegate)
|
||||
{
|
||||
m_openURLDelegate = delegate;
|
||||
m_renderer->SetXamlOpenURLDelegate(delegate);
|
||||
}
|
||||
|
||||
|
||||
bool Direct3DInterop::SendCocos2dEvent(Cocos2dEvent event)
|
||||
{
|
||||
|
|
|
@ -60,6 +60,7 @@ public:
|
|||
void OnCocos2dKeyEvent(Cocos2dKeyEvent key);
|
||||
void OnCocos2dKeyEvent(Cocos2dKeyEvent key, Platform::String^ text);
|
||||
void OnCocos2dEditboxEvent(Platform::Object^ sender, Platform::String^ args, Windows::Foundation::EventHandler<Platform::String^>^ handler);
|
||||
void OnCocos2dOpenURL(Platform::String^ url);
|
||||
|
||||
property Windows::Graphics::Display::DisplayOrientations WindowOrientation;
|
||||
property Windows::Foundation::Size WindowBounds;
|
||||
|
@ -67,6 +68,7 @@ public:
|
|||
void SetCocos2dEventDelegate(Cocos2dEventDelegate^ delegate);
|
||||
void SetCocos2dMessageBoxDelegate(Cocos2dMessageBoxDelegate ^ delegate);
|
||||
void SetCocos2dEditBoxDelegate(Cocos2dEditBoxDelegate ^ delegate);
|
||||
void SetCocos2dOpenURLDelegate(Cocos2dOpenURLDelegate ^ delegate);
|
||||
|
||||
|
||||
protected:
|
||||
|
@ -90,6 +92,7 @@ private:
|
|||
Cocos2dEventDelegate^ m_delegate;
|
||||
Cocos2dMessageBoxDelegate^ m_messageBoxDelegate;
|
||||
Cocos2dEditBoxDelegate^ m_editBoxDelegate;
|
||||
Cocos2dOpenURLDelegate^ m_openURLDelegate;
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue