mirror of https://github.com/axmolengine/axmol.git
Enable screen orientation change handling - by Teivaz
This commit is contained in:
parent
3bcc3e014d
commit
7a2a44ad88
|
@ -123,6 +123,16 @@ void BackButtonEvent::execute()
|
||||||
GLViewImpl::sharedOpenGLView()->OnBackKeyPress();
|
GLViewImpl::sharedOpenGLView()->OnBackKeyPress();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CustomInputEvent::CustomInputEvent(const std::function<void()>& fun)
|
||||||
|
: m_fun(fun)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
void CustomInputEvent::execute()
|
||||||
|
{
|
||||||
|
m_fun();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
||||||
|
|
|
@ -99,6 +99,15 @@ public:
|
||||||
virtual void execute();
|
virtual void execute();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class CustomInputEvent : public InputEvent
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CustomInputEvent(const std::function<void()>&);
|
||||||
|
virtual void execute();
|
||||||
|
private:
|
||||||
|
std::function<void()> m_fun;
|
||||||
|
};
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
||||||
#endif // #ifndef __INPUT_EVENT__
|
#endif // #ifndef __INPUT_EVENT__
|
||||||
|
|
|
@ -109,6 +109,15 @@ void Direct3DInterop::OnPointerReleased(DrawingSurfaceManipulationHost^ sender,
|
||||||
cocos2d::GLViewImpl::sharedOpenGLView()->QueuePointerEvent(cocos2d::PointerEventType::PointerReleased, args);
|
cocos2d::GLViewImpl::sharedOpenGLView()->QueuePointerEvent(cocos2d::PointerEventType::PointerReleased, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Direct3DInterop::OnOrientationChanged(Windows::Graphics::Display::DisplayOrientations orientation)
|
||||||
|
{
|
||||||
|
std::shared_ptr<cocos2d::InputEvent> e(new cocos2d::CustomInputEvent([this, orientation]()
|
||||||
|
{
|
||||||
|
m_renderer->OnOrientationChanged(orientation);
|
||||||
|
}));
|
||||||
|
cocos2d::GLViewImpl::sharedOpenGLView()->QueueEvent(e);
|
||||||
|
}
|
||||||
|
|
||||||
void Direct3DInterop::OnCocos2dKeyEvent(Cocos2dKeyEvent key)
|
void Direct3DInterop::OnCocos2dKeyEvent(Cocos2dKeyEvent key)
|
||||||
{
|
{
|
||||||
std::shared_ptr<cocos2d::InputEvent> e(new cocos2d::KeyboardEvent(key));
|
std::shared_ptr<cocos2d::InputEvent> e(new cocos2d::KeyboardEvent(key));
|
||||||
|
@ -147,13 +156,6 @@ HRESULT Direct3DInterop::PrepareResources(_In_ const LARGE_INTEGER* presentTarge
|
||||||
HRESULT Direct3DInterop::Draw(_In_ ID3D11Device1* device, _In_ ID3D11DeviceContext1* context, _In_ ID3D11RenderTargetView* renderTargetView)
|
HRESULT Direct3DInterop::Draw(_In_ ID3D11Device1* device, _In_ ID3D11DeviceContext1* context, _In_ ID3D11RenderTargetView* renderTargetView)
|
||||||
{
|
{
|
||||||
m_renderer->UpdateDevice(device, context, renderTargetView);
|
m_renderer->UpdateDevice(device, context, renderTargetView);
|
||||||
#if 0
|
|
||||||
if(mCurrentOrientation != WindowOrientation)
|
|
||||||
{
|
|
||||||
mCurrentOrientation = WindowOrientation;
|
|
||||||
m_renderer->OnOrientationChanged(mCurrentOrientation);
|
|
||||||
}
|
|
||||||
#endif // 0
|
|
||||||
|
|
||||||
cocos2d::GLViewImpl::sharedOpenGLView()->ProcessEvents();
|
cocos2d::GLViewImpl::sharedOpenGLView()->ProcessEvents();
|
||||||
m_renderer->Render();
|
m_renderer->Render();
|
||||||
|
|
|
@ -60,6 +60,7 @@ public:
|
||||||
void OnCocos2dKeyEvent(Cocos2dKeyEvent key);
|
void OnCocos2dKeyEvent(Cocos2dKeyEvent key);
|
||||||
void OnCocos2dKeyEvent(Cocos2dKeyEvent key, Platform::String^ text);
|
void OnCocos2dKeyEvent(Cocos2dKeyEvent key, Platform::String^ text);
|
||||||
void OnCocos2dEditboxEvent(Platform::Object^ sender, Platform::String^ args, Windows::Foundation::EventHandler<Platform::String^>^ handler);
|
void OnCocos2dEditboxEvent(Platform::Object^ sender, Platform::String^ args, Windows::Foundation::EventHandler<Platform::String^>^ handler);
|
||||||
|
void OnOrientationChanged(Windows::Graphics::Display::DisplayOrientations orientation);
|
||||||
void OnCocos2dOpenURL(Platform::String^ url);
|
void OnCocos2dOpenURL(Platform::String^ url);
|
||||||
|
|
||||||
property Windows::Graphics::Display::DisplayOrientations WindowOrientation;
|
property Windows::Graphics::Display::DisplayOrientations WindowOrientation;
|
||||||
|
|
|
@ -51,33 +51,42 @@ namespace PhoneDirect3DXamlAppInterop
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override protected void OnOrientationChanged(OrientationChangedEventArgs args)
|
||||||
|
{
|
||||||
|
base.OnOrientationChanged(args);
|
||||||
|
if (m_d3dInterop != null)
|
||||||
|
{
|
||||||
|
DisplayOrientations orientation = ConvertToNativeOrientation(args.Orientation);
|
||||||
|
m_d3dInterop.OnOrientationChanged(orientation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static DisplayOrientations ConvertToNativeOrientation(PageOrientation xamlOrientation)
|
||||||
|
{
|
||||||
|
switch (xamlOrientation)
|
||||||
|
{
|
||||||
|
case PageOrientation.Portrait:
|
||||||
|
case PageOrientation.PortraitUp:
|
||||||
|
return DisplayOrientations.Portrait;
|
||||||
|
case PageOrientation.PortraitDown:
|
||||||
|
return DisplayOrientations.PortraitFlipped;
|
||||||
|
case PageOrientation.Landscape:
|
||||||
|
case PageOrientation.LandscapeLeft:
|
||||||
|
return DisplayOrientations.Landscape;
|
||||||
|
case PageOrientation.LandscapeRight:
|
||||||
|
return DisplayOrientations.LandscapeFlipped;
|
||||||
|
default:
|
||||||
|
return DisplayOrientations.Landscape;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void DrawingSurfaceBackground_Loaded(object sender, RoutedEventArgs e)
|
private void DrawingSurfaceBackground_Loaded(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
if (m_d3dInterop == null)
|
if (m_d3dInterop == null)
|
||||||
{
|
{
|
||||||
PageOrientation pageOrientation = (PageOrientation)GetValue(OrientationProperty);
|
PageOrientation pageOrientation = (PageOrientation)GetValue(OrientationProperty);
|
||||||
DisplayOrientations displayOrientation;
|
DisplayOrientations displayOrientation = ConvertToNativeOrientation(pageOrientation);
|
||||||
|
|
||||||
switch(pageOrientation)
|
|
||||||
{
|
|
||||||
case PageOrientation.Portrait:
|
|
||||||
case PageOrientation.PortraitUp:
|
|
||||||
displayOrientation = DisplayOrientations.Portrait;
|
|
||||||
break;
|
|
||||||
case PageOrientation.PortraitDown:
|
|
||||||
displayOrientation = DisplayOrientations.PortraitFlipped;
|
|
||||||
break;
|
|
||||||
case PageOrientation.Landscape:
|
|
||||||
case PageOrientation.LandscapeLeft:
|
|
||||||
displayOrientation = DisplayOrientations.Landscape;
|
|
||||||
break;
|
|
||||||
case PageOrientation.LandscapeRight:
|
|
||||||
displayOrientation = DisplayOrientations.LandscapeFlipped;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
displayOrientation = DisplayOrientations.Landscape;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
m_d3dInterop = new Direct3DInterop(displayOrientation);
|
m_d3dInterop = new Direct3DInterop(displayOrientation);
|
||||||
|
|
||||||
// Set WindowBounds to size of DrawingSurface
|
// Set WindowBounds to size of DrawingSurface
|
||||||
|
|
|
@ -51,33 +51,42 @@ namespace PhoneDirect3DXamlAppInterop
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override protected void OnOrientationChanged(OrientationChangedEventArgs args)
|
||||||
|
{
|
||||||
|
base.OnOrientationChanged(args);
|
||||||
|
if (m_d3dInterop != null)
|
||||||
|
{
|
||||||
|
DisplayOrientations orientation = ConvertToNativeOrientation(args.Orientation);
|
||||||
|
m_d3dInterop.OnOrientationChanged(orientation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static DisplayOrientations ConvertToNativeOrientation(PageOrientation xamlOrientation)
|
||||||
|
{
|
||||||
|
switch (xamlOrientation)
|
||||||
|
{
|
||||||
|
case PageOrientation.Portrait:
|
||||||
|
case PageOrientation.PortraitUp:
|
||||||
|
return DisplayOrientations.Portrait;
|
||||||
|
case PageOrientation.PortraitDown:
|
||||||
|
return DisplayOrientations.PortraitFlipped;
|
||||||
|
case PageOrientation.Landscape:
|
||||||
|
case PageOrientation.LandscapeLeft:
|
||||||
|
return DisplayOrientations.Landscape;
|
||||||
|
case PageOrientation.LandscapeRight:
|
||||||
|
return DisplayOrientations.LandscapeFlipped;
|
||||||
|
default:
|
||||||
|
return DisplayOrientations.Landscape;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void DrawingSurfaceBackground_Loaded(object sender, RoutedEventArgs e)
|
private void DrawingSurfaceBackground_Loaded(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
if (m_d3dInterop == null)
|
if (m_d3dInterop == null)
|
||||||
{
|
{
|
||||||
PageOrientation pageOrientation = (PageOrientation)GetValue(OrientationProperty);
|
PageOrientation pageOrientation = (PageOrientation)GetValue(OrientationProperty);
|
||||||
DisplayOrientations displayOrientation;
|
DisplayOrientations displayOrientation = ConvertToNativeOrientation(pageOrientation);
|
||||||
|
|
||||||
switch(pageOrientation)
|
|
||||||
{
|
|
||||||
case PageOrientation.Portrait:
|
|
||||||
case PageOrientation.PortraitUp:
|
|
||||||
displayOrientation = DisplayOrientations.Portrait;
|
|
||||||
break;
|
|
||||||
case PageOrientation.PortraitDown:
|
|
||||||
displayOrientation = DisplayOrientations.PortraitFlipped;
|
|
||||||
break;
|
|
||||||
case PageOrientation.Landscape:
|
|
||||||
case PageOrientation.LandscapeLeft:
|
|
||||||
displayOrientation = DisplayOrientations.Landscape;
|
|
||||||
break;
|
|
||||||
case PageOrientation.LandscapeRight:
|
|
||||||
displayOrientation = DisplayOrientations.LandscapeFlipped;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
displayOrientation = DisplayOrientations.Landscape;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
m_d3dInterop = new Direct3DInterop(displayOrientation);
|
m_d3dInterop = new Direct3DInterop(displayOrientation);
|
||||||
|
|
||||||
// Set WindowBounds to size of DrawingSurface
|
// Set WindowBounds to size of DrawingSurface
|
||||||
|
|
|
@ -109,6 +109,15 @@ void Direct3DInterop::OnPointerReleased(DrawingSurfaceManipulationHost^ sender,
|
||||||
cocos2d::GLViewImpl::sharedOpenGLView()->QueuePointerEvent(cocos2d::PointerEventType::PointerReleased, args);
|
cocos2d::GLViewImpl::sharedOpenGLView()->QueuePointerEvent(cocos2d::PointerEventType::PointerReleased, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Direct3DInterop::OnOrientationChanged(Windows::Graphics::Display::DisplayOrientations orientation)
|
||||||
|
{
|
||||||
|
std::shared_ptr<cocos2d::InputEvent> e(new cocos2d::CustomInputEvent([this, orientation]()
|
||||||
|
{
|
||||||
|
m_renderer->OnOrientationChanged(orientation);
|
||||||
|
}));
|
||||||
|
cocos2d::GLViewImpl::sharedOpenGLView()->QueueEvent(e);
|
||||||
|
}
|
||||||
|
|
||||||
void Direct3DInterop::OnCocos2dKeyEvent(Cocos2dKeyEvent key)
|
void Direct3DInterop::OnCocos2dKeyEvent(Cocos2dKeyEvent key)
|
||||||
{
|
{
|
||||||
std::shared_ptr<cocos2d::InputEvent> e(new cocos2d::KeyboardEvent(key));
|
std::shared_ptr<cocos2d::InputEvent> e(new cocos2d::KeyboardEvent(key));
|
||||||
|
@ -147,13 +156,6 @@ HRESULT Direct3DInterop::PrepareResources(_In_ const LARGE_INTEGER* presentTarge
|
||||||
HRESULT Direct3DInterop::Draw(_In_ ID3D11Device1* device, _In_ ID3D11DeviceContext1* context, _In_ ID3D11RenderTargetView* renderTargetView)
|
HRESULT Direct3DInterop::Draw(_In_ ID3D11Device1* device, _In_ ID3D11DeviceContext1* context, _In_ ID3D11RenderTargetView* renderTargetView)
|
||||||
{
|
{
|
||||||
m_renderer->UpdateDevice(device, context, renderTargetView);
|
m_renderer->UpdateDevice(device, context, renderTargetView);
|
||||||
#if 0
|
|
||||||
if(mCurrentOrientation != WindowOrientation)
|
|
||||||
{
|
|
||||||
mCurrentOrientation = WindowOrientation;
|
|
||||||
m_renderer->OnOrientationChanged(mCurrentOrientation);
|
|
||||||
}
|
|
||||||
#endif // 0
|
|
||||||
|
|
||||||
cocos2d::GLViewImpl::sharedOpenGLView()->ProcessEvents();
|
cocos2d::GLViewImpl::sharedOpenGLView()->ProcessEvents();
|
||||||
m_renderer->Render();
|
m_renderer->Render();
|
||||||
|
@ -188,10 +190,10 @@ void Direct3DInterop::SetCocos2dOpenURLDelegate(Cocos2dOpenURLDelegate ^ delegat
|
||||||
|
|
||||||
bool Direct3DInterop::SendCocos2dEvent(Cocos2dEvent event)
|
bool Direct3DInterop::SendCocos2dEvent(Cocos2dEvent event)
|
||||||
{
|
{
|
||||||
std::string str;
|
Platform::String^ str;
|
||||||
if(m_delegate)
|
if(m_delegate)
|
||||||
{
|
{
|
||||||
m_delegate->Invoke(event, stringToPlatformString(str));
|
m_delegate->Invoke(event, str);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -60,6 +60,7 @@ public:
|
||||||
void OnCocos2dKeyEvent(Cocos2dKeyEvent key);
|
void OnCocos2dKeyEvent(Cocos2dKeyEvent key);
|
||||||
void OnCocos2dKeyEvent(Cocos2dKeyEvent key, Platform::String^ text);
|
void OnCocos2dKeyEvent(Cocos2dKeyEvent key, Platform::String^ text);
|
||||||
void OnCocos2dEditboxEvent(Platform::Object^ sender, Platform::String^ args, Windows::Foundation::EventHandler<Platform::String^>^ handler);
|
void OnCocos2dEditboxEvent(Platform::Object^ sender, Platform::String^ args, Windows::Foundation::EventHandler<Platform::String^>^ handler);
|
||||||
|
void OnOrientationChanged(Windows::Graphics::Display::DisplayOrientations orientation);
|
||||||
void OnCocos2dOpenURL(Platform::String^ url);
|
void OnCocos2dOpenURL(Platform::String^ url);
|
||||||
|
|
||||||
property Windows::Graphics::Display::DisplayOrientations WindowOrientation;
|
property Windows::Graphics::Display::DisplayOrientations WindowOrientation;
|
||||||
|
|
Loading…
Reference in New Issue