Improve API GLViewImpl::createWithRect

This commit is contained in:
halx99 2023-03-11 22:53:55 +08:00
parent b46417809d
commit 1e66a93868
7 changed files with 19 additions and 75 deletions

View File

@ -50,7 +50,7 @@ void initExtensions()
NS_AX_BEGIN 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; auto ret = new GLViewImpl;
if (ret && ret->initWithRect(viewName, rect, frameZoomFactor)) if (ret && ret->initWithRect(viewName, rect, frameZoomFactor))
@ -93,7 +93,7 @@ GLViewImpl::GLViewImpl()
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; return true;
} }

View File

@ -36,7 +36,7 @@ class AX_DLL GLViewImpl : public GLView
public: public:
// static function // static function
static GLViewImpl* create(std::string_view viewname); 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); static GLViewImpl* createWithFullScreen(std::string_view viewName);
bool isOpenGLReady() override; bool isOpenGLReady() override;
@ -49,7 +49,7 @@ protected:
GLViewImpl(); GLViewImpl();
virtual ~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); bool initWithFullScreen(std::string_view viewName);
}; };

View File

@ -389,7 +389,7 @@ GLViewImpl* GLViewImpl::create(std::string_view viewName, bool resizable)
return nullptr; 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; auto ret = new GLViewImpl;
if (ret->initWithRect(viewName, rect, frameZoomFactor, resizable)) if (ret->initWithRect(viewName, rect, frameZoomFactor, resizable))
@ -427,7 +427,7 @@ GLViewImpl* GLViewImpl::createWithFullScreen(std::string_view viewName,
return nullptr; 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); setViewName(viewName);

View File

@ -41,7 +41,7 @@ public:
static GLViewImpl* create(std::string_view viewName); static GLViewImpl* create(std::string_view viewName);
static GLViewImpl* create(std::string_view viewName, bool resizable); static GLViewImpl* create(std::string_view viewName, bool resizable);
static GLViewImpl* createWithRect(std::string_view viewName, static GLViewImpl* createWithRect(std::string_view viewName,
Rect size, const Rect& size,
float frameZoomFactor = 1.0f, float frameZoomFactor = 1.0f,
bool resizable = false); bool resizable = false);
static GLViewImpl* createWithFullScreen(std::string_view viewName); static GLViewImpl* createWithFullScreen(std::string_view viewName);
@ -135,7 +135,7 @@ protected:
GLViewImpl(bool initglfw = true); GLViewImpl(bool initglfw = true);
virtual ~GLViewImpl(); 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);
bool initWithFullscreen(std::string_view viewname, const GLFWvidmode& videoMode, GLFWmonitor* monitor); bool initWithFullscreen(std::string_view viewname, const GLFWvidmode& videoMode, GLFWmonitor* monitor);
#if (AX_TARGET_PLATFORM != AX_PLATFORM_MAC) // Windows, Linux: use glad to loadGL #if (AX_TARGET_PLATFORM != AX_PLATFORM_MAC) // Windows, Linux: use glad to loadGL

View File

@ -74,17 +74,12 @@ GLViewImpl* GLViewImpl::create(std::string_view viewName)
return nullptr; return nullptr;
} }
GLViewImpl* GLViewImpl::create(std::string_view viewName, GLViewImpl* GLViewImpl::createWithRect(std::string_view viewName,
const Vec2& viewSize, const Rect& rect, float frameZoomFactor)
Windows::Graphics::Display::DisplayOrientations orientation,
float dpi)
{ {
auto ret = new GLViewImpl; 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(); ret->autorelease();
return ret; return ret;
} }
@ -125,11 +120,12 @@ GLViewImpl::~GLViewImpl()
// TODO: cleanup // 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); setViewName(viewName);
setFrameSize(rect.size.width, rect.size.height); setFrameSize(rect.size.width, rect.size.height);
setFrameZoomFactor(frameZoomFactor); setFrameZoomFactor(frameZoomFactor);
UpdateForWindowSizeChange(rect.size.width, rect.size.height);
return true; 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); 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) void ax::GLViewImpl::setCursorVisible(bool isVisible)
{ {
_isCursorVisible = 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() void GLViewImpl::UpdateWindowSize()
{ {
float width, height; float width, height;
@ -561,25 +532,6 @@ ax::Vec2 GLViewImpl::TransformToOrientation(Windows::Foundation::Point p)
float y = p.Y; float y = p.Y;
returnValue = Vec2(x, 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(); float zoomFactor = GLViewImpl::sharedOpenGLView()->getFrameZoomFactor();
if (zoomFactor > 0.0f) if (zoomFactor > 0.0f)
{ {

View File

@ -48,10 +48,7 @@ class AX_DLL GLViewImpl : public GLView
{ {
public: public:
static GLViewImpl* create(std::string_view viewName); static GLViewImpl* create(std::string_view viewName);
static GLViewImpl* create(std::string_view viewName, static GLViewImpl* createWithRect(std::string_view viewName, const Rect& rect, float frameZoomFactor = 1.0f);
const Vec2& viewSize,
Windows::Graphics::Display::DisplayOrientations orientation,
float dpi);
/* override functions */ /* override functions */
virtual bool isOpenGLReady(); virtual bool isOpenGLReady();
@ -64,11 +61,6 @@ public:
virtual void setIMEKeyboardState(bool bOpen) override; virtual void setIMEKeyboardState(bool bOpen) override;
virtual void setIMEKeyboardState(bool bOpen, std::string_view str); 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. * Hide or Show the mouse cursor if there is one.
* *
@ -128,7 +120,6 @@ public:
void SetDPI(float dpi) { m_dpi = dpi; } void SetDPI(float dpi) { m_dpi = dpi; }
float GetDPI() { return m_dpi; } float GetDPI() { return m_dpi; }
// static function // static function
/** /**
@brief get the shared main open gl window @brief get the shared main open gl window
@ -141,7 +132,7 @@ protected:
GLViewImpl(); GLViewImpl();
virtual ~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); bool initWithFullScreen(std::string_view viewName);
/* /*
@ -173,7 +164,6 @@ private:
float m_width; float m_width;
float m_height; float m_height;
float m_dpi; float m_dpi;
Windows::Graphics::Display::DisplayOrientations m_orientation; Windows::Graphics::Display::DisplayOrientations m_orientation;
Windows::Foundation::Rect m_keyboardRect; Windows::Foundation::Rect m_keyboardRect;

View File

@ -59,8 +59,10 @@ void AxmolRenderer::Resume()
if (!glview) if (!glview)
{ {
GLViewImpl* glview = GLViewImpl::create( GLViewImpl* glview = GLViewImpl::createWithRect(
"axmol", Vec2{static_cast<float>(m_width), static_cast<float>(m_height)}, m_orientation, m_dpi); "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->setDispatcher(m_dispatcher.Get());
glview->setPanel(m_panel.Get()); glview->setPanel(m_panel.Get());
director->setOpenGLView(glview); director->setOpenGLView(glview);