From c71eb041b690fd94fa06ef7bd0819a410bb1c8fb Mon Sep 17 00:00:00 2001 From: jp9000 Date: Tue, 31 Dec 2013 04:02:07 -0700 Subject: [PATCH] fix startup resize issue on osx --- obs/window-basic-main.cpp | 44 +++++++++++++++++++++++---------------- obs/window-basic-main.hpp | 2 ++ 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/obs/window-basic-main.cpp b/obs/window-basic-main.cpp index f2a1f5102..2a674fd15 100644 --- a/obs/window-basic-main.cpp +++ b/obs/window-basic-main.cpp @@ -119,13 +119,9 @@ OBSBasic::~OBSBasic() bool OBSBasic::InitGraphics() { - wxSize size = previewPanel->GetClientSize(); - struct obs_video_info ovi; wxGetApp().GetConfigFPS(ovi.fps_num, ovi.fps_den); ovi.graphics_module = wxGetApp().GetRenderModule(); - ovi.window_width = size.x; - ovi.window_height = size.y; ovi.base_width = (uint32_t)config_get_uint(GetGlobalConfig(), "Video", "BaseCX"); ovi.base_height = (uint32_t)config_get_uint(GetGlobalConfig(), @@ -138,12 +134,17 @@ bool OBSBasic::InitGraphics() ovi.adapter = 0; ovi.window = WxToGSWindow(previewPanel); + //required to make opengl display stuff on osx(?) + ResizePreview(ovi.base_width, ovi.base_height); + SendSizeEvent(); + + wxSize size = previewPanel->GetMinSize(); + ovi.window_width = size.x; + ovi.window_height = size.y; + if (!obs_reset_video(&ovi)) return false; - //required to make opengl display stuff on osx(?) - SendSizeEvent(); - return true; } @@ -158,6 +159,22 @@ void OBSBasic::OnMinimize(wxIconizeEvent &event) event.Skip(); } +void OBSBasic::ResizePreview(uint32_t cx, uint32_t cy) +{ + /* resize preview panel to fix to the top section of the window */ + wxSize targetSize = GetPreviewContainer()->GetSize(); + double targetAspect = double(targetSize.x) / double(targetSize.y); + double baseAspect = double(cx) / double(cy); + wxSize newSize; + + if (targetAspect > baseAspect) + newSize = wxSize(targetSize.y * baseAspect, targetSize.y); + else + newSize = wxSize(targetSize.x, targetSize.x / baseAspect); + + GetPreviewPanel()->SetMinSize(newSize); +} + void OBSBasic::OnSize(wxSizeEvent &event) { struct obs_video_info ovi; @@ -167,18 +184,9 @@ void OBSBasic::OnSize(wxSizeEvent &event) if (!obs_get_video_info(&ovi)) return; - /* resize preview panel to fix to the top section of the window */ - wxSize targetSize = GetPreviewContainer()->GetSize(); - double targetAspect = double(targetSize.x) / double(targetSize.y); - double baseAspect = double(ovi.base_width) / double(ovi.base_height); - wxSize newSize; + ResizePreview(ovi.base_width, ovi.base_height); + wxSize newSize = previewPanel->GetMinSize(); - if (targetAspect > baseAspect) - newSize = wxSize(targetSize.y * baseAspect, targetSize.y); - else - newSize = wxSize(targetSize.x, targetSize.x / baseAspect); - - GetPreviewPanel()->SetMinSize(newSize); gs_entercontext(obs_graphics()); gs_resize(newSize.x, newSize.y); gs_leavecontext(); diff --git a/obs/window-basic-main.hpp b/obs/window-basic-main.hpp index f44f56d5b..d3b5e1cfe 100644 --- a/obs/window-basic-main.hpp +++ b/obs/window-basic-main.hpp @@ -28,6 +28,8 @@ class OBSBasic : public OBSBasicBase { static void SourceAdded(void *data, calldata_t params); static void SourceDestroyed(void *data, calldata_t params); + void ResizePreview(uint32_t cx, uint32_t cy); + void AddSource(obs_scene_t scene, const char *id); void AddSourcePopup();