UI: Limit preview scrolling

This prevents the preview from being scrolled on forever.
This commit is contained in:
cg2121 2023-03-08 12:20:10 -06:00 committed by Jim
parent f55b251fa8
commit b82c8ccdcf
3 changed files with 26 additions and 0 deletions

View file

@ -4665,6 +4665,7 @@ void OBSBasic::ResizePreview(uint32_t cx, uint32_t cy)
obs_get_video_info(&ovi);
if (isFixedScaling) {
ui->preview->ClampScrollingOffsets();
previewScale = ui->preview->GetScalingAmount();
GetCenterPosFromFixedScale(
int(cx), int(cy),

View file

@ -9,6 +9,7 @@
#include "window-basic-main.hpp"
#include "obs-app.hpp"
#include "platform.hpp"
#include "display-helpers.hpp"
#define HANDLE_RADIUS 4.0f
#define HANDLE_SEL_RADIUS (HANDLE_RADIUS * 1.5f)
@ -2606,3 +2607,26 @@ void OBSBasicPreview::DrawSpacingHelpers()
vec3_set(&end, 1.0f, right.y, 1.0f);
RenderSpacingHelper(3, start, end, viewport, pixelRatio);
}
void OBSBasicPreview::ClampScrollingOffsets()
{
obs_video_info ovi;
obs_get_video_info(&ovi);
QSize targetSize = GetPixelSize(this);
vec3 target, offset;
vec3_set(&target, (float)targetSize.width(), (float)targetSize.height(),
1.0f);
vec3_set(&offset, (float)ovi.base_width, (float)ovi.base_height, 1.0f);
vec3_mulf(&offset, &offset, scalingAmount);
vec3_sub(&offset, &offset, &target);
vec3_mulf(&offset, &offset, 0.5f);
vec3_maxf(&offset, &offset, 0.0f);
scrollingOffset.x = std::clamp(scrollingOffset.x, -offset.x, offset.x);
scrollingOffset.y = std::clamp(scrollingOffset.y, -offset.y, offset.y);
}

View file

@ -197,4 +197,5 @@ public:
int spacerPx[4] = {0};
void DrawSpacingHelpers();
void ClampScrollingOffsets();
};