mirror of https://github.com/axmolengine/axmol.git
Improve API GLViewImpl::createWithRect
This commit is contained in:
parent
b46417809d
commit
1e66a93868
|
@ -50,7 +50,7 @@ void initExtensions()
|
|||
|
||||
NS_AX_BEGIN
|
||||
|
||||
GLViewImpl* GLViewImpl::createWithRect(std::string_view viewName, Rect rect, float frameZoomFactor)
|
||||
GLViewImpl* GLViewImpl::createWithRect(std::string_view viewName, const Rect& rect, float frameZoomFactor)
|
||||
{
|
||||
auto ret = new GLViewImpl;
|
||||
if (ret && ret->initWithRect(viewName, rect, frameZoomFactor))
|
||||
|
@ -93,7 +93,7 @@ GLViewImpl::GLViewImpl()
|
|||
|
||||
GLViewImpl::~GLViewImpl() {}
|
||||
|
||||
bool GLViewImpl::initWithRect(std::string_view viewName, Rect rect, float frameZoomFactor)
|
||||
bool GLViewImpl::initWithRect(std::string_view viewName, const Rect& rect, float frameZoomFactor)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ class AX_DLL GLViewImpl : public GLView
|
|||
public:
|
||||
// static function
|
||||
static GLViewImpl* create(std::string_view viewname);
|
||||
static GLViewImpl* createWithRect(std::string_view viewName, Rect rect, float frameZoomFactor = 1.0f);
|
||||
static GLViewImpl* createWithRect(std::string_view viewName, const Rect& rect, float frameZoomFactor = 1.0f);
|
||||
static GLViewImpl* createWithFullScreen(std::string_view viewName);
|
||||
|
||||
bool isOpenGLReady() override;
|
||||
|
@ -49,7 +49,7 @@ protected:
|
|||
GLViewImpl();
|
||||
virtual ~GLViewImpl();
|
||||
|
||||
bool initWithRect(std::string_view viewName, Rect rect, float frameZoomFactor);
|
||||
bool initWithRect(std::string_view viewName, const Rect& rect, float frameZoomFactor);
|
||||
bool initWithFullScreen(std::string_view viewName);
|
||||
};
|
||||
|
||||
|
|
|
@ -389,7 +389,7 @@ GLViewImpl* GLViewImpl::create(std::string_view viewName, bool resizable)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
GLViewImpl* GLViewImpl::createWithRect(std::string_view viewName, ax::Rect rect, float frameZoomFactor, bool resizable)
|
||||
GLViewImpl* GLViewImpl::createWithRect(std::string_view viewName, const ax::Rect& rect, float frameZoomFactor, bool resizable)
|
||||
{
|
||||
auto ret = new GLViewImpl;
|
||||
if (ret->initWithRect(viewName, rect, frameZoomFactor, resizable))
|
||||
|
@ -427,7 +427,7 @@ GLViewImpl* GLViewImpl::createWithFullScreen(std::string_view viewName,
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
bool GLViewImpl::initWithRect(std::string_view viewName, ax::Rect rect, float frameZoomFactor, bool resizable)
|
||||
bool GLViewImpl::initWithRect(std::string_view viewName, const ax::Rect& rect, float frameZoomFactor, bool resizable)
|
||||
{
|
||||
setViewName(viewName);
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ public:
|
|||
static GLViewImpl* create(std::string_view viewName);
|
||||
static GLViewImpl* create(std::string_view viewName, bool resizable);
|
||||
static GLViewImpl* createWithRect(std::string_view viewName,
|
||||
Rect size,
|
||||
const Rect& size,
|
||||
float frameZoomFactor = 1.0f,
|
||||
bool resizable = false);
|
||||
static GLViewImpl* createWithFullScreen(std::string_view viewName);
|
||||
|
@ -135,7 +135,7 @@ protected:
|
|||
GLViewImpl(bool initglfw = true);
|
||||
virtual ~GLViewImpl();
|
||||
|
||||
bool initWithRect(std::string_view viewName, Rect rect, float frameZoomFactor, bool resizable);
|
||||
bool initWithRect(std::string_view viewName, const Rect& rect, float frameZoomFactor, bool resizable);
|
||||
bool initWithFullScreen(std::string_view viewName);
|
||||
bool initWithFullscreen(std::string_view viewname, const GLFWvidmode& videoMode, GLFWmonitor* monitor);
|
||||
#if (AX_TARGET_PLATFORM != AX_PLATFORM_MAC) // Windows, Linux: use glad to loadGL
|
||||
|
|
|
@ -74,17 +74,12 @@ GLViewImpl* GLViewImpl::create(std::string_view viewName)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
GLViewImpl* GLViewImpl::create(std::string_view viewName,
|
||||
const Vec2& viewSize,
|
||||
Windows::Graphics::Display::DisplayOrientations orientation,
|
||||
float dpi)
|
||||
GLViewImpl* GLViewImpl::createWithRect(std::string_view viewName,
|
||||
const Rect& rect, float frameZoomFactor)
|
||||
{
|
||||
auto ret = new GLViewImpl;
|
||||
if (ret && ret->initWithFullScreen(viewName))
|
||||
if (ret && ret->initWithRect(viewName, rect, frameZoomFactor))
|
||||
{
|
||||
ret->m_orientation = orientation;
|
||||
ret->m_dpi = dpi;
|
||||
ret->UpdateForWindowSizeChange(viewSize.x, viewSize.y);
|
||||
ret->autorelease();
|
||||
return ret;
|
||||
}
|
||||
|
@ -125,11 +120,12 @@ GLViewImpl::~GLViewImpl()
|
|||
// TODO: cleanup
|
||||
}
|
||||
|
||||
bool GLViewImpl::initWithRect(std::string_view viewName, Rect rect, float frameZoomFactor)
|
||||
bool GLViewImpl::initWithRect(std::string_view viewName, const Rect& rect, float frameZoomFactor)
|
||||
{
|
||||
setViewName(viewName);
|
||||
setFrameSize(rect.size.width, rect.size.height);
|
||||
setFrameZoomFactor(frameZoomFactor);
|
||||
UpdateForWindowSizeChange(rect.size.width, rect.size.height);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -138,14 +134,6 @@ bool GLViewImpl::initWithFullScreen(std::string_view viewName)
|
|||
return initWithRect(viewName, Rect(0, 0, m_width, m_height), 1.0f);
|
||||
}
|
||||
|
||||
bool GLViewImpl::Create(float width, float height, float dpi, DisplayOrientations orientation)
|
||||
{
|
||||
m_orientation = orientation;
|
||||
m_dpi = dpi;
|
||||
UpdateForWindowSizeChange(width, height);
|
||||
return true;
|
||||
}
|
||||
|
||||
void ax::GLViewImpl::setCursorVisible(bool isVisible)
|
||||
{
|
||||
_isCursorVisible = isVisible;
|
||||
|
@ -509,23 +497,6 @@ void GLViewImpl::UpdateForWindowSizeChange(float width, float height)
|
|||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
win32 version
|
||||
|
||||
void GLViewEventHandler::OnGLFWWindowSizeFunCallback(GLFWwindow *windows, int width, int height)
|
||||
{
|
||||
auto view = Director::getInstance()->getOpenGLView();
|
||||
if(view && view->getResolutionPolicy() != ResolutionPolicy::UNKNOWN)
|
||||
{
|
||||
Size resSize=view->getDesignResolutionSize();
|
||||
ResolutionPolicy resPolicy=view->getResolutionPolicy();
|
||||
view->setFrameSize(width, height);
|
||||
view->setDesignResolutionSize(resSize.width, resSize.height, resPolicy);
|
||||
Director::getInstance()->setViewport();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void GLViewImpl::UpdateWindowSize()
|
||||
{
|
||||
float width, height;
|
||||
|
@ -561,25 +532,6 @@ ax::Vec2 GLViewImpl::TransformToOrientation(Windows::Foundation::Point p)
|
|||
float y = p.Y;
|
||||
returnValue = Vec2(x, y);
|
||||
|
||||
#if 0
|
||||
switch (m_orientation)
|
||||
{
|
||||
case DisplayOrientations::Portrait:
|
||||
default:
|
||||
returnValue = Vec2(x, y);
|
||||
break;
|
||||
case DisplayOrientations::Landscape:
|
||||
returnValue = Vec2(y, m_width - x);
|
||||
break;
|
||||
case DisplayOrientations::PortraitFlipped:
|
||||
returnValue = Vec2(m_width - x, m_height - y);
|
||||
break;
|
||||
case DisplayOrientations::LandscapeFlipped:
|
||||
returnValue = Vec2(m_height - y, x);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
float zoomFactor = GLViewImpl::sharedOpenGLView()->getFrameZoomFactor();
|
||||
if (zoomFactor > 0.0f)
|
||||
{
|
||||
|
|
|
@ -48,10 +48,7 @@ class AX_DLL GLViewImpl : public GLView
|
|||
{
|
||||
public:
|
||||
static GLViewImpl* create(std::string_view viewName);
|
||||
static GLViewImpl* create(std::string_view viewName,
|
||||
const Vec2& viewSize,
|
||||
Windows::Graphics::Display::DisplayOrientations orientation,
|
||||
float dpi);
|
||||
static GLViewImpl* createWithRect(std::string_view viewName, const Rect& rect, float frameZoomFactor = 1.0f);
|
||||
|
||||
/* override functions */
|
||||
virtual bool isOpenGLReady();
|
||||
|
@ -64,11 +61,6 @@ public:
|
|||
virtual void setIMEKeyboardState(bool bOpen) override;
|
||||
virtual void setIMEKeyboardState(bool bOpen, std::string_view str);
|
||||
|
||||
virtual bool Create(float width,
|
||||
float height,
|
||||
float dpi,
|
||||
Windows::Graphics::Display::DisplayOrientations orientation);
|
||||
|
||||
/**
|
||||
* Hide or Show the mouse cursor if there is one.
|
||||
*
|
||||
|
@ -128,7 +120,6 @@ public:
|
|||
|
||||
void SetDPI(float dpi) { m_dpi = dpi; }
|
||||
float GetDPI() { return m_dpi; }
|
||||
|
||||
// static function
|
||||
/**
|
||||
@brief get the shared main open gl window
|
||||
|
@ -141,7 +132,7 @@ protected:
|
|||
GLViewImpl();
|
||||
virtual ~GLViewImpl();
|
||||
|
||||
bool initWithRect(std::string_view viewName, Rect rect, float frameZoomFactor);
|
||||
bool initWithRect(std::string_view viewName, const Rect& rect, float frameZoomFactor);
|
||||
bool initWithFullScreen(std::string_view viewName);
|
||||
|
||||
/*
|
||||
|
@ -173,7 +164,6 @@ private:
|
|||
float m_width;
|
||||
float m_height;
|
||||
float m_dpi;
|
||||
|
||||
Windows::Graphics::Display::DisplayOrientations m_orientation;
|
||||
Windows::Foundation::Rect m_keyboardRect;
|
||||
|
||||
|
|
|
@ -59,8 +59,10 @@ void AxmolRenderer::Resume()
|
|||
|
||||
if (!glview)
|
||||
{
|
||||
GLViewImpl* glview = GLViewImpl::create(
|
||||
"axmol", Vec2{static_cast<float>(m_width), static_cast<float>(m_height)}, m_orientation, m_dpi);
|
||||
GLViewImpl* glview = GLViewImpl::createWithRect(
|
||||
"AXMOL10", ax::Rect{0, 0, static_cast<float>(m_width), static_cast<float>(m_height)});
|
||||
glview->UpdateOrientation(m_orientation);
|
||||
glview->SetDPI(m_dpi);
|
||||
glview->setDispatcher(m_dispatcher.Get());
|
||||
glview->setPanel(m_panel.Get());
|
||||
director->setOpenGLView(glview);
|
||||
|
|
Loading…
Reference in New Issue