mirror of https://github.com/axmolengine/axmol.git
added DPI support for universal app
This commit is contained in:
parent
6d46ee8f3d
commit
510c8caed7
|
@ -49,7 +49,7 @@ Cocos2dRenderer::Cocos2dRenderer(int width, int height, float dpi, CoreDispatche
|
|||
GLViewImpl* glview = GLViewImpl::create("Test Cpp");
|
||||
glview->setDispatcher(dispatcher);
|
||||
glview->setPanel(panel);
|
||||
glview->Create(static_cast<float>(width), static_cast<float>(height), DisplayOrientations::Landscape);
|
||||
glview->Create(static_cast<float>(width), static_cast<float>(height), dpi, DisplayOrientations::Landscape);
|
||||
director->setOpenGLView(glview);
|
||||
CCApplication::getInstance()->run();
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ void Cocos2dRenderer::Draw(GLsizei width, GLsizei height, float dpi)
|
|||
if (dpi != m_dpi)
|
||||
{
|
||||
m_dpi = dpi;
|
||||
GLViewImpl::sharedOpenGLView()->UpdateDPI(m_dpi);
|
||||
GLViewImpl::sharedOpenGLView()->SetDPI(m_dpi);
|
||||
}
|
||||
|
||||
GLViewImpl::sharedOpenGLView()->ProcessEvents();
|
||||
|
|
|
@ -35,39 +35,46 @@ using namespace Windows::Graphics::Display;
|
|||
USING_NS_CC;
|
||||
|
||||
|
||||
Cocos2dRenderer::Cocos2dRenderer(const int width, const int height, CoreDispatcher^ dispatcher, Panel^ panel)
|
||||
: mApp(nullptr)
|
||||
, mWidth(width)
|
||||
, mHeight(height)
|
||||
Cocos2dRenderer::Cocos2dRenderer(int width, int height, float dpi, CoreDispatcher^ dispatcher, Panel^ panel)
|
||||
: m_app(nullptr)
|
||||
, m_width(width)
|
||||
, m_height(height)
|
||||
, m_dpi(dpi)
|
||||
, m_dispatcher(dispatcher)
|
||||
, m_panel(panel)
|
||||
{
|
||||
mApp = new AppDelegate();
|
||||
m_app = new AppDelegate();
|
||||
auto director = cocos2d::Director::getInstance();
|
||||
|
||||
GLViewImpl* glview = GLViewImpl::create("Test Cpp");
|
||||
glview->setDispatcher(dispatcher);
|
||||
glview->setPanel(panel);
|
||||
glview->Create(static_cast<float>(width), static_cast<float>(height), DisplayOrientations::Landscape);
|
||||
glview->Create(static_cast<float>(width), static_cast<float>(height), dpi, DisplayOrientations::Landscape);
|
||||
director->setOpenGLView(glview);
|
||||
CCApplication::getInstance()->run();
|
||||
}
|
||||
|
||||
Cocos2dRenderer::~Cocos2dRenderer()
|
||||
{
|
||||
delete mApp;
|
||||
delete m_app;
|
||||
}
|
||||
|
||||
// Draws a basic triangle
|
||||
void Cocos2dRenderer::Draw(GLsizei width, GLsizei height)
|
||||
void Cocos2dRenderer::Draw(GLsizei width, GLsizei height, float dpi)
|
||||
{
|
||||
if (width != mWidth || height != mHeight)
|
||||
if (width != m_width || height != m_height)
|
||||
{
|
||||
mWidth = width;
|
||||
mHeight = height;
|
||||
m_width = width;
|
||||
m_height = height;
|
||||
GLViewImpl::sharedOpenGLView()->UpdateForWindowSizeChange(static_cast<float>(width), static_cast<float>(height));
|
||||
}
|
||||
|
||||
if (dpi != m_dpi)
|
||||
{
|
||||
m_dpi = dpi;
|
||||
GLViewImpl::sharedOpenGLView()->SetDPI(m_dpi);
|
||||
}
|
||||
|
||||
GLViewImpl::sharedOpenGLView()->ProcessEvents();
|
||||
GLViewImpl::sharedOpenGLView()->Render();
|
||||
}
|
||||
|
|
|
@ -29,18 +29,20 @@ namespace cocos2d
|
|||
class Cocos2dRenderer
|
||||
{
|
||||
public:
|
||||
Cocos2dRenderer(const int width, const int height, Windows::UI::Core::CoreDispatcher^ dispathcer, Windows::UI::Xaml::Controls::Panel^ panel);
|
||||
Cocos2dRenderer( int width, int height, float dpi, Windows::UI::Core::CoreDispatcher^ dispathcer, Windows::UI::Xaml::Controls::Panel^ panel);
|
||||
~Cocos2dRenderer();
|
||||
void Draw(GLsizei width, GLsizei height);
|
||||
void Draw(GLsizei width, GLsizei height, float dpi);
|
||||
void QueuePointerEvent(PointerEventType type, Windows::UI::Core::PointerEventArgs^ args);
|
||||
void QueueKeyBoardEvent(Cocos2dKeyEvent type, Windows::UI::Core::KeyEventArgs^ e);
|
||||
|
||||
private:
|
||||
|
||||
int mWidth;
|
||||
int mHeight;
|
||||
int m_width;
|
||||
int m_height;
|
||||
float m_dpi;
|
||||
|
||||
// The AppDelegate for the Cocos2D app
|
||||
AppDelegate* mApp;
|
||||
AppDelegate* m_app;
|
||||
Platform::Agile<Windows::UI::Core::CoreDispatcher> m_dispatcher;
|
||||
Platform::Agile<Windows::UI::Xaml::Controls::Panel> m_panel;
|
||||
};
|
||||
|
|
|
@ -47,7 +47,8 @@ OpenGLESPage::OpenGLESPage(OpenGLES* openGLES) :
|
|||
mRenderSurface(EGL_NO_SURFACE),
|
||||
mCustomRenderSurfaceSize(0,0),
|
||||
mUseCustomRenderSurfaceSize(false),
|
||||
m_coreInput(nullptr)
|
||||
m_coreInput(nullptr),
|
||||
m_dpi(0.0f)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
|
@ -238,16 +239,20 @@ void OpenGLESPage::StartRenderLoop()
|
|||
GLsizei panelHeight = 0;
|
||||
GetSwapChainPanelSize(&panelWidth, &panelHeight);
|
||||
|
||||
DisplayInformation^ currentDisplayInformation = DisplayInformation::GetForCurrentView();
|
||||
|
||||
m_dpi = currentDisplayInformation->LogicalDpi;
|
||||
|
||||
if (m_renderer.get() == nullptr)
|
||||
{
|
||||
m_renderer = std::make_shared<Cocos2dRenderer>(panelWidth, panelHeight, dispatcher, swapChainPanel);
|
||||
m_renderer = std::make_shared<Cocos2dRenderer>(panelWidth, panelHeight, m_dpi, dispatcher, swapChainPanel);
|
||||
}
|
||||
|
||||
while (action->Status == Windows::Foundation::AsyncStatus::Started)
|
||||
{
|
||||
|
||||
GetSwapChainPanelSize(&panelWidth, &panelHeight);
|
||||
m_renderer.get()->Draw(panelWidth, panelHeight);
|
||||
m_renderer.get()->Draw(panelWidth, panelHeight, m_dpi);
|
||||
|
||||
// The call to eglSwapBuffers might not be successful (i.e. due to Device Lost)
|
||||
// If the call fails, then we must reinitialize EGL and the GL resources.
|
||||
|
|
|
@ -67,5 +67,7 @@ namespace cocos2d
|
|||
void OnPointerPressed(Platform::Object^ sender, Windows::UI::Core::PointerEventArgs^ e);
|
||||
void OnPointerMoved(Platform::Object^ sender, Windows::UI::Core::PointerEventArgs^ e);
|
||||
void OnPointerReleased(Platform::Object^ sender, Windows::UI::Core::PointerEventArgs^ e);
|
||||
|
||||
float m_dpi;
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue