Many fixes in win32 platform
This commit is contained in:
parent
d1d8b79edc
commit
ddd3f84ad7
|
@ -25,7 +25,7 @@ if(WIN32)
|
||||||
-I${CMAKE_CURRENT_SOURCE_DIR}/src
|
-I${CMAKE_CURRENT_SOURCE_DIR}/src
|
||||||
-i${CMAKE_CURRENT_SOURCE_DIR}/src/otcicon.rc
|
-i${CMAKE_CURRENT_SOURCE_DIR}/src/otcicon.rc
|
||||||
-o ${CMAKE_CURRENT_BINARY_DIR}/otcicon.o)
|
-o ${CMAKE_CURRENT_BINARY_DIR}/otcicon.o)
|
||||||
SET(executable_SOURCES ${executable_SOURCES} otcicon.o)
|
set(executable_SOURCES ${executable_SOURCES} otcicon.o)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# add otclient executable
|
# add otclient executable
|
||||||
|
|
|
@ -35,6 +35,7 @@ end
|
||||||
|
|
||||||
function Client.init()
|
function Client.init()
|
||||||
g_window.setMinimumSize({ width = 600, height = 480 })
|
g_window.setMinimumSize({ width = 600, height = 480 })
|
||||||
|
g_sounds.preload("startup.ogg")
|
||||||
|
|
||||||
-- initialize in fullscreen mode on mobile devices
|
-- initialize in fullscreen mode on mobile devices
|
||||||
if g_window.getPlatformType() == "X11-EGL" then
|
if g_window.getPlatformType() == "X11-EGL" then
|
||||||
|
|
|
@ -52,6 +52,7 @@ public:
|
||||||
int getLastFps() { return m_lastFps; }
|
int getLastFps() { return m_lastFps; }
|
||||||
int getPartialFps() { return (int)m_partialFps; }
|
int getPartialFps() { return (int)m_partialFps; }
|
||||||
int getMaxFps() { return m_maxFps; }
|
int getMaxFps() { return m_maxFps; }
|
||||||
|
int getFrames() { return m_frames; }
|
||||||
float getMediumFrameDelay() { return m_mediumFrameDelay; }
|
float getMediumFrameDelay() { return m_mediumFrameDelay; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -108,8 +108,7 @@ void GraphicalApplication::run()
|
||||||
|
|
||||||
g_lua.callGlobalField("g_app", "onRun");
|
g_lua.callGlobalField("g_app", "onRun");
|
||||||
|
|
||||||
// show the application only after we draw some frames
|
g_window.show();
|
||||||
g_dispatcher.scheduleEvent([] { g_window.show(); }, 10);
|
|
||||||
|
|
||||||
while(!m_stopping) {
|
while(!m_stopping) {
|
||||||
// poll all events before rendering
|
// poll all events before rendering
|
||||||
|
|
|
@ -70,6 +70,7 @@ public:
|
||||||
|
|
||||||
Size getUnmaximizedSize() { return m_unmaximizedSize; }
|
Size getUnmaximizedSize() { return m_unmaximizedSize; }
|
||||||
Size getSize() { return m_size; }
|
Size getSize() { return m_size; }
|
||||||
|
Size getMinimumSize() { return m_minimumSize; }
|
||||||
int getWidth() { return m_size.width(); }
|
int getWidth() { return m_size.width(); }
|
||||||
int getHeight() { return m_size.height(); }
|
int getHeight() { return m_size.height(); }
|
||||||
Point getUnmaximizedPos() { return m_unmaximizedPos; }
|
Point getUnmaximizedPos() { return m_unmaximizedPos; }
|
||||||
|
@ -105,6 +106,7 @@ protected:
|
||||||
Timer m_keyPressTimer;
|
Timer m_keyPressTimer;
|
||||||
|
|
||||||
Size m_size;
|
Size m_size;
|
||||||
|
Size m_minimumSize;
|
||||||
Point m_position;
|
Point m_position;
|
||||||
Size m_unmaximizedSize;
|
Size m_unmaximizedSize;
|
||||||
Point m_unmaximizedPos;
|
Point m_unmaximizedPos;
|
||||||
|
|
|
@ -37,6 +37,8 @@ WIN32Window::WIN32Window()
|
||||||
m_deviceContext = 0;
|
m_deviceContext = 0;
|
||||||
m_cursor = 0;
|
m_cursor = 0;
|
||||||
m_minimumSize = Size(600,480);
|
m_minimumSize = Size(600,480);
|
||||||
|
m_size = Size(600,480);
|
||||||
|
m_hidden = true;
|
||||||
|
|
||||||
#ifdef OPENGL_ES
|
#ifdef OPENGL_ES
|
||||||
m_eglConfig = 0;
|
m_eglConfig = 0;
|
||||||
|
@ -264,21 +266,19 @@ void WIN32Window::internalCreateWindow()
|
||||||
DWORD dwStyle = WS_OVERLAPPEDWINDOW;
|
DWORD dwStyle = WS_OVERLAPPEDWINDOW;
|
||||||
|
|
||||||
// initialize in the center of the screen
|
// initialize in the center of the screen
|
||||||
m_size = m_minimumSize;
|
|
||||||
m_position = ((getDisplaySize() - m_size) / 2).toPoint();
|
m_position = ((getDisplaySize() - m_size) / 2).toPoint();
|
||||||
|
|
||||||
RECT windowRect = {m_position.x, m_position.y, m_position.x + m_size.width(), m_position.y + m_size.height()};
|
Rect screenRect = adjustWindowRect(Rect(m_position, m_size));
|
||||||
AdjustWindowRectEx(&windowRect, dwStyle, FALSE, dwExStyle);
|
|
||||||
|
|
||||||
updateUnmaximizedCoords();
|
updateUnmaximizedCoords();
|
||||||
m_window = CreateWindowExA(dwExStyle,
|
m_window = CreateWindowExA(dwExStyle,
|
||||||
g_app.getCompactName().c_str(),
|
g_app.getCompactName().c_str(),
|
||||||
NULL,
|
NULL,
|
||||||
dwStyle,
|
dwStyle,
|
||||||
windowRect.left,
|
screenRect.left(),
|
||||||
windowRect.top,
|
screenRect.top(),
|
||||||
windowRect.right - windowRect.left,
|
screenRect.width(),
|
||||||
windowRect.bottom - windowRect.top,
|
screenRect.height(),
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
m_instance,
|
m_instance,
|
||||||
|
@ -444,50 +444,45 @@ void *WIN32Window::getExtensionProcAddress(const char *ext)
|
||||||
|
|
||||||
void WIN32Window::move(const Point& pos)
|
void WIN32Window::move(const Point& pos)
|
||||||
{
|
{
|
||||||
RECT clientRect;
|
Rect clientRect(pos, getClientRect().size());
|
||||||
GetClientRect(m_window, &clientRect);
|
Rect windowRect = adjustWindowRect(clientRect);
|
||||||
|
MoveWindow(m_window, windowRect.x(), windowRect.y(), windowRect.width(), windowRect.height(), TRUE);
|
||||||
RECT windowRect = {pos.x, pos.y, clientRect.right - clientRect.left, clientRect.bottom - clientRect.top};
|
if(m_hidden)
|
||||||
AdjustWindowRectEx(&windowRect, WS_OVERLAPPEDWINDOW, FALSE, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
|
ShowWindow(m_window, SW_HIDE);
|
||||||
|
|
||||||
int x = windowRect.left;
|
|
||||||
int y = windowRect.top;
|
|
||||||
GetWindowRect(m_window, &windowRect);
|
|
||||||
int width = windowRect.right - windowRect.left;
|
|
||||||
int height = windowRect.bottom - windowRect.top;
|
|
||||||
|
|
||||||
MoveWindow(m_window, x, y, width, height, TRUE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WIN32Window::resize(const Size& size)
|
void WIN32Window::resize(const Size& size)
|
||||||
{
|
{
|
||||||
RECT windowRect;
|
if(size.width() < m_minimumSize.width() || size.height() < m_minimumSize.height())
|
||||||
RECT clientRect;
|
return;
|
||||||
|
Rect clientRect(getClientRect().topLeft(), size);
|
||||||
GetWindowRect(m_window, &windowRect);
|
Rect windowRect = adjustWindowRect(clientRect);
|
||||||
GetClientRect(m_window, &clientRect);
|
MoveWindow(m_window, windowRect.x(), windowRect.y(), windowRect.width(), windowRect.height(), TRUE);
|
||||||
|
if(m_hidden)
|
||||||
int x = windowRect.left;
|
ShowWindow(m_window, SW_HIDE);
|
||||||
int y = windowRect.top;
|
|
||||||
int width = size.width() + ((windowRect.right - windowRect.left) - (clientRect.right - clientRect.left));
|
|
||||||
int height = size.height() + ((windowRect.bottom - windowRect.top) - (clientRect.bottom - clientRect.top));
|
|
||||||
|
|
||||||
MoveWindow(m_window, x, y, width, height, TRUE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WIN32Window::show()
|
void WIN32Window::show()
|
||||||
{
|
{
|
||||||
ShowWindow(m_window, SW_SHOW);
|
m_hidden = false;
|
||||||
|
if(m_maximized)
|
||||||
|
ShowWindow(m_window, SW_MAXIMIZE);
|
||||||
|
else
|
||||||
|
ShowWindow(m_window, SW_SHOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WIN32Window::hide()
|
void WIN32Window::hide()
|
||||||
{
|
{
|
||||||
|
m_hidden = true;
|
||||||
ShowWindow(m_window, SW_HIDE);
|
ShowWindow(m_window, SW_HIDE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WIN32Window::maximize()
|
void WIN32Window::maximize()
|
||||||
{
|
{
|
||||||
ShowWindow(m_window, SW_MAXIMIZE);
|
if(!m_hidden)
|
||||||
|
ShowWindow(m_window, SW_MAXIMIZE);
|
||||||
|
else
|
||||||
|
m_maximized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WIN32Window::poll()
|
void WIN32Window::poll()
|
||||||
|
@ -697,8 +692,9 @@ LRESULT WIN32Window::windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar
|
||||||
}
|
}
|
||||||
case WM_GETMINMAXINFO: {
|
case WM_GETMINMAXINFO: {
|
||||||
LPMINMAXINFO pMMI = (LPMINMAXINFO)lParam;
|
LPMINMAXINFO pMMI = (LPMINMAXINFO)lParam;
|
||||||
pMMI->ptMinTrackSize.x = m_minimumSize.width();
|
Rect adjustedRect = adjustWindowRect(Rect(getWindowRect().topLeft(), m_minimumSize));
|
||||||
pMMI->ptMinTrackSize.y = m_minimumSize.height();
|
pMMI->ptMinTrackSize.x = adjustedRect.width();
|
||||||
|
pMMI->ptMinTrackSize.y = adjustedRect.height();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WM_SIZE: {
|
case WM_SIZE: {
|
||||||
|
@ -722,9 +718,9 @@ LRESULT WIN32Window::windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar
|
||||||
if(m_visible && m_deviceContext)
|
if(m_visible && m_deviceContext)
|
||||||
internalRestoreGLContext();
|
internalRestoreGLContext();
|
||||||
|
|
||||||
Size size;
|
Size size = Size(LOWORD(lParam), HIWORD(lParam));
|
||||||
size.setWidth(std::max(std::min((int)LOWORD(lParam), 7680), m_minimumSize.width()));
|
size.setWidth(std::max(std::min(size.width(), 7680), 32));
|
||||||
size.setHeight(std::max(std::min((int)HIWORD(lParam), 4320), m_minimumSize.height()));
|
size.setHeight(std::max(std::min(size.height(), 4320), 32));
|
||||||
|
|
||||||
if(m_visible && (forceResize || m_size != size)) {
|
if(m_visible && (forceResize || m_size != size)) {
|
||||||
m_size = size;
|
m_size = size;
|
||||||
|
@ -837,23 +833,22 @@ void WIN32Window::setFullscreen(bool fullscreen)
|
||||||
if(m_fullscreen == fullscreen)
|
if(m_fullscreen == fullscreen)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
m_fullscreen = fullscreen;
|
||||||
|
|
||||||
DWORD dwStyle = GetWindowLong(m_window, GWL_STYLE);
|
DWORD dwStyle = GetWindowLong(m_window, GWL_STYLE);
|
||||||
static WINDOWPLACEMENT wpPrev;
|
static WINDOWPLACEMENT wpPrev;
|
||||||
wpPrev.length = sizeof(wpPrev);
|
wpPrev.length = sizeof(wpPrev);
|
||||||
|
|
||||||
if(fullscreen) {
|
if(fullscreen) {
|
||||||
|
Size size = getDisplaySize();
|
||||||
GetWindowPlacement(m_window, &wpPrev);
|
GetWindowPlacement(m_window, &wpPrev);
|
||||||
SetWindowLong(m_window, GWL_STYLE, dwStyle & ~WS_OVERLAPPEDWINDOW);
|
SetWindowLong(m_window, GWL_STYLE, (dwStyle & ~WS_OVERLAPPEDWINDOW) | WS_POPUP | WS_EX_TOPMOST);
|
||||||
SetWindowPos(m_window, HWND_TOP, 0, 0, getDisplayWidth(), getDisplayHeight(),
|
SetWindowPos(m_window, HWND_TOPMOST, 0, 0, size.width(), size.height(), SWP_FRAMECHANGED);
|
||||||
SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
|
|
||||||
} else {
|
} else {
|
||||||
SetWindowLong(m_window, GWL_STYLE, dwStyle | WS_OVERLAPPEDWINDOW);
|
SetWindowLong(m_window, GWL_STYLE, (dwStyle & ~(WS_POPUP | WS_EX_TOPMOST)) | WS_OVERLAPPEDWINDOW);
|
||||||
SetWindowPlacement(m_window, &wpPrev);
|
SetWindowPlacement(m_window, &wpPrev);
|
||||||
SetWindowPos(m_window, NULL, 0, 0, 0, 0,
|
SetWindowPos(m_window, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
|
||||||
SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_fullscreen = fullscreen;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WIN32Window::setVerticalSync(bool enable)
|
void WIN32Window::setVerticalSync(bool enable)
|
||||||
|
@ -968,4 +963,43 @@ std::string WIN32Window::getPlatformType()
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Rect WIN32Window::getClientRect()
|
||||||
|
{
|
||||||
|
RECT clientRect = {0,0,0,0};
|
||||||
|
int ret = GetClientRect(m_window, &clientRect);
|
||||||
|
assert(ret != 0);
|
||||||
|
return Rect(Point(clientRect.left, clientRect.top), Point(clientRect.right, clientRect.bottom));
|
||||||
|
}
|
||||||
|
|
||||||
|
Rect WIN32Window::getWindowRect()
|
||||||
|
{
|
||||||
|
RECT windowRect = {0,0,0,0};
|
||||||
|
int ret = GetWindowRect(m_window, &windowRect);
|
||||||
|
assert(ret != 0);
|
||||||
|
return Rect(Point(windowRect.left, windowRect.top), Point(windowRect.right, windowRect.bottom));
|
||||||
|
}
|
||||||
|
|
||||||
|
Rect WIN32Window::adjustWindowRect(const Rect& clientRect)
|
||||||
|
{
|
||||||
|
Rect rect;
|
||||||
|
DWORD dwStyle;
|
||||||
|
DWORD dwExStyle;
|
||||||
|
RECT windowRect = { clientRect.left(), clientRect.top(), clientRect.right(), clientRect.bottom() };
|
||||||
|
if(m_window) {
|
||||||
|
dwStyle = GetWindowLong(m_window, GWL_STYLE);
|
||||||
|
dwExStyle = GetWindowLong(m_window, GWL_EXSTYLE);
|
||||||
|
} else {
|
||||||
|
dwStyle = WS_OVERLAPPEDWINDOW;
|
||||||
|
dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
|
||||||
|
}
|
||||||
|
if(AdjustWindowRectEx(&windowRect, dwStyle, FALSE, dwExStyle) != 0) {
|
||||||
|
rect = Rect(Point(windowRect.left, windowRect.top), Point(windowRect.right, windowRect.bottom));
|
||||||
|
} else {
|
||||||
|
g_logger.traceError("AdjustWindowRectEx failed");
|
||||||
|
rect = Rect(0,0, m_minimumSize);
|
||||||
|
}
|
||||||
|
return rect;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -79,12 +79,16 @@ public:
|
||||||
std::string getPlatformType();
|
std::string getPlatformType();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Rect getClientRect();
|
||||||
|
Rect getWindowRect();
|
||||||
|
Rect adjustWindowRect(const Rect& rect);
|
||||||
|
|
||||||
HWND m_window;
|
HWND m_window;
|
||||||
HINSTANCE m_instance;
|
HINSTANCE m_instance;
|
||||||
HDC m_deviceContext;
|
HDC m_deviceContext;
|
||||||
HCURSOR m_cursor;
|
HCURSOR m_cursor;
|
||||||
HCURSOR m_defaultCursor;
|
HCURSOR m_defaultCursor;
|
||||||
Size m_minimumSize;
|
bool m_hidden;
|
||||||
|
|
||||||
#ifdef OPENGL_ES
|
#ifdef OPENGL_ES
|
||||||
EGLConfig m_eglConfig;
|
EGLConfig m_eglConfig;
|
||||||
|
|
|
@ -40,6 +40,7 @@ X11Window::X11Window()
|
||||||
m_xic = 0;
|
m_xic = 0;
|
||||||
m_screen = 0;
|
m_screen = 0;
|
||||||
m_wmDelete = 0;
|
m_wmDelete = 0;
|
||||||
|
m_minimumSize = Size(600,480);
|
||||||
m_size = Size(600,480);
|
m_size = Size(600,480);
|
||||||
|
|
||||||
#ifdef OPENGL_ES
|
#ifdef OPENGL_ES
|
||||||
|
@ -520,6 +521,8 @@ void X11Window::move(const Point& pos)
|
||||||
|
|
||||||
void X11Window::resize(const Size& size)
|
void X11Window::resize(const Size& size)
|
||||||
{
|
{
|
||||||
|
if(size.width() < m_minimumSize.width() || size.height() < m_minimumSize.height())
|
||||||
|
return;
|
||||||
XResizeWindow(m_display, m_window, size.width(), size.height());
|
XResizeWindow(m_display, m_window, size.width(), size.height());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue