mirror of https://github.com/axmolengine/axmol.git
Merge pull request #8171 from huangshiwu/v3_Teivaz
Enable screen orientation change handling - by Teivaz
This commit is contained in:
commit
8a5829631d
|
@ -123,6 +123,16 @@ void BackButtonEvent::execute()
|
|||
GLViewImpl::sharedOpenGLView()->OnBackKeyPress();
|
||||
}
|
||||
|
||||
CustomInputEvent::CustomInputEvent(const std::function<void()>& fun)
|
||||
: m_fun(fun)
|
||||
{
|
||||
}
|
||||
void CustomInputEvent::execute()
|
||||
{
|
||||
m_fun();
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_CC_END
|
||||
|
||||
|
|
|
@ -99,6 +99,15 @@ public:
|
|||
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
|
||||
|
||||
#endif // #ifndef __INPUT_EVENT__
|
||||
|
|
|
@ -109,6 +109,15 @@ void Direct3DInterop::OnPointerReleased(DrawingSurfaceManipulationHost^ sender,
|
|||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
m_renderer->UpdateDevice(device, context, renderTargetView);
|
||||
#if 0
|
||||
if(mCurrentOrientation != WindowOrientation)
|
||||
{
|
||||
mCurrentOrientation = WindowOrientation;
|
||||
m_renderer->OnOrientationChanged(mCurrentOrientation);
|
||||
}
|
||||
#endif // 0
|
||||
|
||||
cocos2d::GLViewImpl::sharedOpenGLView()->ProcessEvents();
|
||||
m_renderer->Render();
|
||||
|
|
|
@ -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 OnOrientationChanged(Windows::Graphics::Display::DisplayOrientations orientation);
|
||||
void OnCocos2dOpenURL(Platform::String^ url);
|
||||
|
||||
property Windows::Graphics::Display::DisplayOrientations WindowOrientation;
|
||||
|
|
|
@ -51,33 +51,42 @@ namespace PhoneDirect3DXamlAppInterop
|
|||
#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)
|
||||
{
|
||||
if (m_d3dInterop == null)
|
||||
{
|
||||
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);
|
||||
|
||||
// Set WindowBounds to size of DrawingSurface
|
||||
|
|
|
@ -51,33 +51,42 @@ namespace PhoneDirect3DXamlAppInterop
|
|||
#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)
|
||||
{
|
||||
if (m_d3dInterop == null)
|
||||
{
|
||||
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);
|
||||
|
||||
// Set WindowBounds to size of DrawingSurface
|
||||
|
|
|
@ -109,6 +109,15 @@ void Direct3DInterop::OnPointerReleased(DrawingSurfaceManipulationHost^ sender,
|
|||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
m_renderer->UpdateDevice(device, context, renderTargetView);
|
||||
#if 0
|
||||
if(mCurrentOrientation != WindowOrientation)
|
||||
{
|
||||
mCurrentOrientation = WindowOrientation;
|
||||
m_renderer->OnOrientationChanged(mCurrentOrientation);
|
||||
}
|
||||
#endif // 0
|
||||
|
||||
cocos2d::GLViewImpl::sharedOpenGLView()->ProcessEvents();
|
||||
m_renderer->Render();
|
||||
|
|
|
@ -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 OnOrientationChanged(Windows::Graphics::Display::DisplayOrientations orientation);
|
||||
void OnCocos2dOpenURL(Platform::String^ url);
|
||||
|
||||
property Windows::Graphics::Display::DisplayOrientations WindowOrientation;
|
||||
|
|
Loading…
Reference in New Issue