Browse Source

UI: Calculate label position using height and border

Warchamp7 1 year ago
parent
commit
40885b6b19
1 changed files with 35 additions and 19 deletions
  1. 35 19
      UI/multiview.cpp

+ 35 - 19
UI/multiview.cpp

@@ -34,9 +34,9 @@ static OBSSource CreateLabel(const char *name, size_t h)
 	OBSDataAutoRelease font = obs_data_create();
 	OBSDataAutoRelease font = obs_data_create();
 
 
 	std::string text;
 	std::string text;
-	text += "  ";
+	text += " ";
 	text += name;
 	text += name;
-	text += "  ";
+	text += " ";
 
 
 #if defined(_WIN32)
 #if defined(_WIN32)
 	obs_data_set_string(font, "face", "Arial");
 	obs_data_set_string(font, "face", "Arial");
@@ -320,7 +320,7 @@ void Multiview::Render(uint32_t cx, uint32_t cy)
 			sourceX = thickness + pvwprgCX / 2;
 			sourceX = thickness + pvwprgCX / 2;
 			sourceY = thickness;
 			sourceY = thickness;
 			labelX = offset + pvwprgCX / 2;
 			labelX = offset + pvwprgCX / 2;
-			labelY = pvwprgCY * 0.85f;
+			labelY = pvwprgCY;
 			if (program) {
 			if (program) {
 				sourceX += pvwprgCX;
 				sourceX += pvwprgCX;
 				labelX += pvwprgCX;
 				labelX += pvwprgCX;
@@ -330,27 +330,27 @@ void Multiview::Render(uint32_t cx, uint32_t cy)
 			sourceX = thickness;
 			sourceX = thickness;
 			sourceY = pvwprgCY + thickness;
 			sourceY = pvwprgCY + thickness;
 			labelX = offset;
 			labelX = offset;
-			labelY = pvwprgCY * 1.85f;
+			labelY = pvwprgCY * 2;
 			if (program) {
 			if (program) {
 				sourceY = thickness;
 				sourceY = thickness;
-				labelY = pvwprgCY * 0.85f;
+				labelY = pvwprgCY;
 			}
 			}
 			break;
 			break;
 		case MultiviewLayout::VERTICAL_RIGHT_8_SCENES:
 		case MultiviewLayout::VERTICAL_RIGHT_8_SCENES:
 			sourceX = pvwprgCX + thickness;
 			sourceX = pvwprgCX + thickness;
 			sourceY = pvwprgCY + thickness;
 			sourceY = pvwprgCY + thickness;
 			labelX = pvwprgCX + offset;
 			labelX = pvwprgCX + offset;
-			labelY = pvwprgCY * 1.85f;
+			labelY = pvwprgCY * 2;
 			if (program) {
 			if (program) {
 				sourceY = thickness;
 				sourceY = thickness;
-				labelY = pvwprgCY * 0.85f;
+				labelY = pvwprgCY;
 			}
 			}
 			break;
 			break;
 		case MultiviewLayout::HORIZONTAL_BOTTOM_8_SCENES:
 		case MultiviewLayout::HORIZONTAL_BOTTOM_8_SCENES:
 			sourceX = thickness;
 			sourceX = thickness;
 			sourceY = pvwprgCY + thickness;
 			sourceY = pvwprgCY + thickness;
 			labelX = offset;
 			labelX = offset;
-			labelY = pvwprgCY * 1.85f;
+			labelY = pvwprgCY * 2;
 			if (program) {
 			if (program) {
 				sourceX += pvwprgCX;
 				sourceX += pvwprgCX;
 				labelX += pvwprgCX;
 				labelX += pvwprgCX;
@@ -367,7 +367,7 @@ void Multiview::Render(uint32_t cx, uint32_t cy)
 			sourceX = thickness;
 			sourceX = thickness;
 			sourceY = thickness;
 			sourceY = thickness;
 			labelX = offset;
 			labelX = offset;
-			labelY = pvwprgCY * 0.85f;
+			labelY = pvwprgCY;
 			if (program) {
 			if (program) {
 				sourceX += pvwprgCX;
 				sourceX += pvwprgCX;
 				labelX += pvwprgCX;
 				labelX += pvwprgCX;
@@ -444,12 +444,16 @@ void Multiview::Render(uint32_t cx, uint32_t cy)
 		offset = labelOffset(multiviewLayout, label, scenesCX);
 		offset = labelOffset(multiviewLayout, label, scenesCX);
 
 
 		gs_matrix_push();
 		gs_matrix_push();
-		gs_matrix_translate3f(sourceX + offset,
-				      (scenesCY * 0.85f) + sourceY, 0.0f);
+		gs_matrix_translate3f(
+			sourceX + offset,
+			sourceY + scenesCY -
+				(obs_source_get_height(label) * ppiScaleY) -
+				(thickness * 3),
+			0.0f);
 		gs_matrix_scale3f(ppiScaleX, ppiScaleY, 1.0f);
 		gs_matrix_scale3f(ppiScaleX, ppiScaleY, 1.0f);
 		drawBox(obs_source_get_width(label),
 		drawBox(obs_source_get_width(label),
-			obs_source_get_height(label) + int(sourceY * 0.015f),
-			labelColor);
+			obs_source_get_height(label) + thicknessx2, labelColor);
+		gs_matrix_translate3f(0, thickness, 0.0f);
 		obs_source_video_render(label);
 		obs_source_video_render(label);
 		gs_matrix_pop();
 		gs_matrix_pop();
 	}
 	}
@@ -499,12 +503,18 @@ void Multiview::Render(uint32_t cx, uint32_t cy)
 	// Draw the Label
 	// Draw the Label
 	if (drawLabel) {
 	if (drawLabel) {
 		gs_matrix_push();
 		gs_matrix_push();
-		gs_matrix_translate3f(labelX, labelY, 0.0f);
+		gs_matrix_translate3f(
+			labelX,
+			labelY -
+				(obs_source_get_height(previewLabel) *
+				 ppiScaleY) -
+				(thickness * 3),
+			0.0f);
 		gs_matrix_scale3f(ppiScaleX, ppiScaleY, 1.0f);
 		gs_matrix_scale3f(ppiScaleX, ppiScaleY, 1.0f);
 		drawBox(obs_source_get_width(previewLabel),
 		drawBox(obs_source_get_width(previewLabel),
-			obs_source_get_height(previewLabel) +
-				int(pvwprgCX * 0.015f),
+			obs_source_get_height(previewLabel) + thicknessx2,
 			labelColor);
 			labelColor);
+		gs_matrix_translate3f(0, thickness, 0.0f);
 		obs_source_video_render(previewLabel);
 		obs_source_video_render(previewLabel);
 		gs_matrix_pop();
 		gs_matrix_pop();
 	}
 	}
@@ -532,12 +542,18 @@ void Multiview::Render(uint32_t cx, uint32_t cy)
 	// Draw the Label
 	// Draw the Label
 	if (drawLabel) {
 	if (drawLabel) {
 		gs_matrix_push();
 		gs_matrix_push();
-		gs_matrix_translate3f(labelX, labelY, 0.0f);
+		gs_matrix_translate3f(
+			labelX,
+			labelY -
+				(obs_source_get_height(programLabel) *
+				 ppiScaleY) -
+				(thickness * 3),
+			0.0f);
 		gs_matrix_scale3f(ppiScaleX, ppiScaleY, 1.0f);
 		gs_matrix_scale3f(ppiScaleX, ppiScaleY, 1.0f);
 		drawBox(obs_source_get_width(programLabel),
 		drawBox(obs_source_get_width(programLabel),
-			obs_source_get_height(programLabel) +
-				int(pvwprgCX * 0.015f),
+			obs_source_get_height(programLabel) + thicknessx2,
 			labelColor);
 			labelColor);
+		gs_matrix_translate3f(0, thickness, 0.0f);
 		obs_source_video_render(programLabel);
 		obs_source_video_render(programLabel);
 		gs_matrix_pop();
 		gs_matrix_pop();
 	}
 	}