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

@ -357,6 +357,7 @@ Basic.Settings.General.WarnBeforeStartingStream="Show confirmation dialog when s
Basic.Settings.General.WarnBeforeStoppingStream="Show confirmation dialog when stopping streams"
Basic.Settings.General.Snapping="Source Alignment Snapping"
Basic.Settings.General.ScreenSnapping="Snap Sources to edge of screen"
Basic.Settings.General.CenterSnapping="Snap Sources to horizontal and vertical center"
Basic.Settings.General.SnapDistance="Snap Sensitivity"
# basic mode 'stream' settings

View File

@ -233,6 +233,16 @@
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QCheckBox" name="centerSnapping">
<property name="text">
<string>Basic.Settings.General.CenterSnapping</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="snapDistance">
<property name="decimals">
@ -3616,6 +3626,22 @@
<x>476</x>
<y>202</y>
</hint>
<hint type="destinationlabel">
<x>515</x>
<y>277</y>
</hint>
</hints>
</connection>
<connection>
<sender>snappingEnabled</sender>
<signal>toggled(bool)</signal>
<receiver>centerSnapping</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>557</x>
<y>207</y>
</hint>
<hint type="destinationlabel">
<x>777</x>
<y>206</y>

View File

@ -343,6 +343,8 @@ bool OBSApp::InitGlobalConfigDefaults()
"SnappingEnabled", true);
config_set_default_bool(globalConfig, "BasicWindow",
"ScreenSnapping", true);
config_set_default_bool(globalConfig, "BasicWindow",
"CenterSnapping", false);
config_set_default_double(globalConfig, "BasicWindow",
"SnapDistance", 10.0);

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;
}

View File

@ -268,6 +268,7 @@ OBSBasicSettings::OBSBasicSettings(QWidget *parent)
HookWidget(ui->warnBeforeStreamStop, CHECK_CHANGED, GENERAL_CHANGED);
HookWidget(ui->snappingEnabled, CHECK_CHANGED, GENERAL_CHANGED);
HookWidget(ui->screenSnapping, CHECK_CHANGED, GENERAL_CHANGED);
HookWidget(ui->centerSnapping, CHECK_CHANGED, GENERAL_CHANGED);
HookWidget(ui->snapDistance, SCROLL_CHANGED, GENERAL_CHANGED);
HookWidget(ui->outputMode, COMBO_CHANGED, OUTPUTS_CHANGED);
HookWidget(ui->streamType, COMBO_CHANGED, STREAM1_CHANGED);
@ -774,6 +775,10 @@ void OBSBasicSettings::LoadGeneralSettings()
"BasicWindow", "ScreenSnapping");
ui->screenSnapping->setChecked(screenSnapping);
bool centerSnapping = config_get_bool(GetGlobalConfig(),
"BasicWindow", "CenterSnapping");
ui->centerSnapping->setChecked(centerSnapping);
double snapDistance = config_get_double(GetGlobalConfig(),
"BasicWindow", "SnapDistance");
ui->snapDistance->setValue(snapDistance);
@ -2062,6 +2067,10 @@ void OBSBasicSettings::SaveGeneralSettings()
config_set_bool(GetGlobalConfig(), "BasicWindow",
"ScreenSnapping",
ui->screenSnapping->isChecked());
if (WidgetChanged(ui->centerSnapping))
config_set_bool(GetGlobalConfig(), "BasicWindow",
"CenterSnapping",
ui->centerSnapping->isChecked());
if (WidgetChanged(ui->snapDistance))
config_set_double(GetGlobalConfig(), "BasicWindow",
"SnapDistance",