Browse Source

UI: Add ability to center items vertically/horizontally

Clayton Groeneveld 6 years ago
parent
commit
977dea4ff0
4 changed files with 58 additions and 5 deletions
  1. 2 0
      UI/data/locale/en-US.ini
  2. 12 0
      UI/forms/OBSBasic.ui
  3. 42 5
      UI/window-basic-main.cpp
  4. 2 0
      UI/window-basic-main.hpp

+ 2 - 0
UI/data/locale/en-US.ini

@@ -534,6 +534,8 @@ Basic.MainMenu.Edit.Transform.FlipVertical="Flip &Vertical"
 Basic.MainMenu.Edit.Transform.FitToScreen="&Fit to screen"
 Basic.MainMenu.Edit.Transform.StretchToScreen="&Stretch to screen"
 Basic.MainMenu.Edit.Transform.CenterToScreen="&Center to screen"
+Basic.MainMenu.Edit.Transform.VerticalCenter="Center Vertically"
+Basic.MainMenu.Edit.Transform.HorizontalCenter="Center Horizontally"
 Basic.MainMenu.Edit.Order="&Order"
 Basic.MainMenu.Edit.Order.MoveUp="Move &Up"
 Basic.MainMenu.Edit.Order.MoveDown="Move &Down"

+ 12 - 0
UI/forms/OBSBasic.ui

@@ -185,6 +185,8 @@
      <addaction name="actionFitToScreen"/>
      <addaction name="actionStretchToScreen"/>
      <addaction name="actionCenterToScreen"/>
+     <addaction name="actionVerticalCenter"/>
+     <addaction name="actionHorizontalCenter"/>
     </widget>
     <widget class="QMenu" name="orderMenu">
      <property name="title">
@@ -1361,6 +1363,16 @@
     <string>Ctrl+D</string>
    </property>
   </action>
+  <action name="actionVerticalCenter">
+   <property name="text">
+    <string>Basic.MainMenu.Edit.Transform.VerticalCenter</string>
+   </property>
+  </action>
+  <action name="actionHorizontalCenter">
+   <property name="text">
+    <string>Basic.MainMenu.Edit.Transform.HorizontalCenter</string>
+   </property>
+  </action>
   <action name="actionFlipHorizontal">
    <property name="text">
     <string>Basic.MainMenu.Edit.Transform.FlipHorizontal</string>

+ 42 - 5
UI/window-basic-main.cpp

@@ -6106,20 +6106,39 @@ void OBSBasic::on_actionStretchToScreen_triggered()
 			&boundsType);
 }
 
-static bool center_to_scene(obs_scene_t *, obs_sceneitem_t *item, void *)
+enum class CenterType {
+	Scene,
+	Vertical,
+	Horizontal
+};
+
+static bool center_to_scene(obs_scene_t *, obs_sceneitem_t *item, void *param)
 {
+	CenterType centerType = *reinterpret_cast<CenterType*>(param);
+
 	vec3 tl, br, itemCenter, screenCenter, offset;
 	obs_video_info ovi;
+	obs_transform_info oti;
 
 	if (obs_sceneitem_is_group(item))
-		obs_sceneitem_group_enum_items(item, center_to_scene, nullptr);
+		obs_sceneitem_group_enum_items(item, center_to_scene,
+				&centerType);
 	if (!obs_sceneitem_selected(item))
 		return true;
 
 	obs_get_video_info(&ovi);
+	obs_sceneitem_get_info(item, &oti);
+
+	if (centerType == CenterType::Scene)
+		vec3_set(&screenCenter, float(ovi.base_width),
+				float(ovi.base_height), 0.0f);
+	else if (centerType == CenterType::Vertical)
+		vec3_set(&screenCenter, float(oti.bounds.x),
+				float(ovi.base_height), 0.0f);
+	else if (centerType == CenterType::Horizontal)
+		vec3_set(&screenCenter, float(ovi.base_width),
+				float(oti.bounds.y), 0.0f);
 
-	vec3_set(&screenCenter, float(ovi.base_width),
-			float(ovi.base_height), 0.0f);
 	vec3_mulf(&screenCenter, &screenCenter, 0.5f);
 
 	GetItemBox(item, tl, br);
@@ -6131,13 +6150,31 @@ static bool center_to_scene(obs_scene_t *, obs_sceneitem_t *item, void *)
 	vec3_sub(&offset, &screenCenter, &itemCenter);
 	vec3_add(&tl, &tl, &offset);
 
+	if (centerType == CenterType::Vertical)
+		tl.x = oti.pos.x;
+	else if (centerType == CenterType::Horizontal)
+		tl.y = oti.pos.y;
+
 	SetItemTL(item, tl);
 	return true;
 };
 
 void OBSBasic::on_actionCenterToScreen_triggered()
 {
-	obs_scene_enum_items(GetCurrentScene(), center_to_scene, nullptr);
+	CenterType centerType = CenterType::Scene;
+	obs_scene_enum_items(GetCurrentScene(), center_to_scene, &centerType);
+}
+
+void OBSBasic::on_actionVerticalCenter_triggered()
+{
+	CenterType centerType = CenterType::Vertical;
+	obs_scene_enum_items(GetCurrentScene(), center_to_scene, &centerType);
+}
+
+void OBSBasic::on_actionHorizontalCenter_triggered()
+{
+	CenterType centerType = CenterType::Horizontal;
+	obs_scene_enum_items(GetCurrentScene(), center_to_scene, &centerType);
 }
 
 void OBSBasic::EnablePreviewDisplay(bool enable)

+ 2 - 0
UI/window-basic-main.hpp

@@ -673,6 +673,8 @@ private slots:
 	void on_actionFitToScreen_triggered();
 	void on_actionStretchToScreen_triggered();
 	void on_actionCenterToScreen_triggered();
+	void on_actionVerticalCenter_triggered();
+	void on_actionHorizontalCenter_triggered();
 
 	void on_scenes_currentItemChanged(QListWidgetItem *current,
 			QListWidgetItem *prev);