From 43d472328c3ceebace932c3c203d3241663d616d Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Sun, 22 Jul 2018 11:16:48 +0300 Subject: [PATCH] - implemented vid_setsize CCMD in Cocoa backend --- src/posix/cocoa/gl_sysfb.h | 38 +++++++++++++++++++++++--------------- src/posix/cocoa/i_video.mm | 35 +++++++++++++++++++++++++++++++++-- 2 files changed, 56 insertions(+), 17 deletions(-) diff --git a/src/posix/cocoa/gl_sysfb.h b/src/posix/cocoa/gl_sysfb.h index fc957a641..9f8222013 100644 --- a/src/posix/cocoa/gl_sysfb.h +++ b/src/posix/cocoa/gl_sysfb.h @@ -57,6 +57,7 @@ public: int GetClientWidth() override; int GetClientHeight() override; void ToggleFullscreen(bool yes) override; + void SetWindowSize(int width, int height) override; void SetMode(bool fullscreen, bool hiDPI); @@ -66,27 +67,34 @@ public: static void SetWindowTitle(const char* title); protected: - CocoaWindow* m_window; - - bool m_fullscreen; - bool m_hiDPI; - - static const uint32_t GAMMA_CHANNEL_SIZE = 256; - static const uint32_t GAMMA_CHANNEL_COUNT = 3; - static const uint32_t GAMMA_TABLE_SIZE = GAMMA_CHANNEL_SIZE * GAMMA_CHANNEL_COUNT; - - bool m_supportsGamma; - uint16_t m_originalGamma[GAMMA_TABLE_SIZE]; - SystemGLFrameBuffer() {} - void SetFullscreenMode(); - void SetWindowedMode(); - void SwapBuffers(); void SetGammaTable(uint16_t* table); void ResetGammaTable(); + + bool m_supportsGamma; + +private: + void SetFullscreenMode(); + void SetWindowedMode(); + + bool m_fullscreen; + bool m_hiDPI; + + CocoaWindow* m_window; + + static const uint32_t GAMMA_CHANNEL_SIZE = 256; + static const uint32_t GAMMA_CHANNEL_COUNT = 3; + static const uint32_t GAMMA_TABLE_SIZE = GAMMA_CHANNEL_SIZE * GAMMA_CHANNEL_COUNT; + + uint16_t m_originalGamma[GAMMA_TABLE_SIZE]; + + int GetTitleBarHeight() const; + + static const int MINIMUM_WIDTH = 320; + static const int MINIMUM_HEIGHT = 200; }; #endif // COCOA_GL_SYSFB_H_INCLUDED diff --git a/src/posix/cocoa/i_video.mm b/src/posix/cocoa/i_video.mm index 03613636d..d6e147cbb 100644 --- a/src/posix/cocoa/i_video.mm +++ b/src/posix/cocoa/i_video.mm @@ -319,9 +319,9 @@ static SystemGLFrameBuffer* frameBuffer; SystemGLFrameBuffer::SystemGLFrameBuffer(void*, const bool fullscreen) : DFrameBuffer(vid_defwidth, vid_defheight) -, m_window(CreateWindow(STYLE_MASK_WINDOWED)) , m_fullscreen(false) , m_hiDPI(false) +, m_window(CreateWindow(STYLE_MASK_WINDOWED)) { SetFlash(0, 0); @@ -388,6 +388,35 @@ void SystemGLFrameBuffer::ToggleFullscreen(bool yes) SetMode(yes, m_hiDPI); } +void SystemGLFrameBuffer::SetWindowSize(int width, int height) +{ + if (width < MINIMUM_WIDTH || height < MINIMUM_HEIGHT) + { + return; + } + + if (fullscreen) + { + // Enter windowed mode in order to calculate title bar height + fullscreen = false; + SetMode(false, m_hiDPI); + } + + win_w = width; + win_h = height + GetTitleBarHeight(); + + SetMode(false, m_hiDPI); +} + +int SystemGLFrameBuffer::GetTitleBarHeight() const +{ + const NSRect windowFrame = [m_window frame]; + const NSRect contentFrame = [m_window contentRectForFrameRect:windowFrame]; + const int titleBarHeight = windowFrame.size.height - contentFrame.size.height; + + return titleBarHeight; +} + void SystemGLFrameBuffer::SetVSync(bool vsync) { @@ -465,7 +494,9 @@ void SystemGLFrameBuffer::SetWindowedMode() [m_window setHidesOnDeactivate:NO]; } - const bool isFrameValid = win_x >= 0 && win_y >= 0 && win_w > 320 && win_h > 200; + const bool isFrameValid = win_x >= 0 && win_y >= 0 + && win_w >= MINIMUM_WIDTH + && win_h - GetTitleBarHeight() >= MINIMUM_HEIGHT; const NSRect frameSize = isFrameValid ? NSMakeRect(win_x, win_y, win_w, win_h) : NSMakeRect(0, 0, vid_defwidth, vid_defheight);