- implemented vid_setsize CCMD in Cocoa backend

This commit is contained in:
alexey.lysiuk 2018-07-22 11:16:48 +03:00
parent 4bb125d76c
commit 43d472328c
2 changed files with 56 additions and 17 deletions

View file

@ -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

View file

@ -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);