UI: Add option to snap to vertical/horizontal center

Allows users to snap sources to the horizontal or vertical centers of
the screen.  Off by default.

Closes jp9000/obs-studio#528
This commit is contained in:
Jeremiah Senkpiel
2016-04-06 18:10:39 -07:00
committed by jp9000
parent ad70d023c4
commit 5911b26578
5 changed files with 52 additions and 0 deletions

View File

@@ -147,9 +147,13 @@ vec3 OBSBasicPreview::GetSnapOffset(const vec3 &tl, const vec3 &br)
const bool screenSnap = config_get_bool(GetGlobalConfig(),
"BasicWindow", "ScreenSnapping");
const bool centerSnap = config_get_bool(GetGlobalConfig(),
"BasicWindow", "CenterSnapping");
const float clampDist = config_get_double(GetGlobalConfig(),
"BasicWindow", "SnapDistance") / main->previewScale;
const float centerX = br.x - (br.x - tl.x) / 2.0f;
const float centerY = br.y - (br.y - tl.y) / 2.0f;
// Left screen edge.
if (screenSnap &&
@@ -160,6 +164,11 @@ vec3 OBSBasicPreview::GetSnapOffset(const vec3 &tl, const vec3 &br)
fabsf(clampOffset.x) < EPSILON &&
fabsf(screenSize.x - br.x) < clampDist)
clampOffset.x = screenSize.x - br.x;
// Horizontal center.
if (centerSnap &&
fabsf(screenSize.x - (br.x - tl.x)) > clampDist &&
fabsf(screenSize.x / 2.0f - centerX) < clampDist)
clampOffset.x = screenSize.x / 2.0f - centerX;
// Top screen edge.
if (screenSnap &&
@@ -170,6 +179,11 @@ vec3 OBSBasicPreview::GetSnapOffset(const vec3 &tl, const vec3 &br)
fabsf(clampOffset.y) < EPSILON &&
fabsf(screenSize.y - br.y) < clampDist)
clampOffset.y = screenSize.y - br.y;
// Vertical center.
if (centerSnap &&
fabsf(screenSize.y - (br.y - tl.y)) > clampDist &&
fabsf(screenSize.y / 2.0f - centerY) < clampDist)
clampOffset.y = screenSize.y / 2.0f - centerY;
return clampOffset;
}