multiview.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777
  1. #include "multiview.hpp"
  2. #include "window-basic-main.hpp"
  3. #include "obs-app.hpp"
  4. #include "platform.hpp"
  5. #include "display-helpers.hpp"
  6. Multiview::Multiview()
  7. {
  8. InitSafeAreas(&actionSafeMargin, &graphicsSafeMargin,
  9. &fourByThreeSafeMargin, &leftLine, &topLine, &rightLine);
  10. }
  11. Multiview::~Multiview()
  12. {
  13. for (OBSWeakSource &weakSrc : multiviewScenes) {
  14. OBSSource src = OBSGetStrongRef(weakSrc);
  15. if (src)
  16. obs_source_dec_showing(src);
  17. }
  18. obs_enter_graphics();
  19. gs_vertexbuffer_destroy(actionSafeMargin);
  20. gs_vertexbuffer_destroy(graphicsSafeMargin);
  21. gs_vertexbuffer_destroy(fourByThreeSafeMargin);
  22. gs_vertexbuffer_destroy(leftLine);
  23. gs_vertexbuffer_destroy(topLine);
  24. gs_vertexbuffer_destroy(rightLine);
  25. obs_leave_graphics();
  26. }
  27. static OBSSource CreateLabel(const char *name, size_t h)
  28. {
  29. OBSDataAutoRelease settings = obs_data_create();
  30. OBSDataAutoRelease font = obs_data_create();
  31. std::string text;
  32. text += " ";
  33. text += name;
  34. text += " ";
  35. #if defined(_WIN32)
  36. obs_data_set_string(font, "face", "Arial");
  37. #elif defined(__APPLE__)
  38. obs_data_set_string(font, "face", "Helvetica");
  39. #else
  40. obs_data_set_string(font, "face", "Monospace");
  41. #endif
  42. obs_data_set_int(font, "flags", 1); // Bold text
  43. obs_data_set_int(font, "size", int(h / 9.81));
  44. obs_data_set_obj(settings, "font", font);
  45. obs_data_set_string(settings, "text", text.c_str());
  46. obs_data_set_bool(settings, "outline", false);
  47. obs_data_set_int(settings, "opacity", 50);
  48. #ifdef _WIN32
  49. const char *text_source_id = "text_gdiplus";
  50. #else
  51. const char *text_source_id = "text_ft2_source";
  52. #endif
  53. OBSSourceAutoRelease txtSource =
  54. obs_source_create_private(text_source_id, name, settings);
  55. return txtSource.Get();
  56. }
  57. void Multiview::Update(MultiviewLayout multiviewLayout, bool drawLabel,
  58. bool drawSafeArea)
  59. {
  60. this->multiviewLayout = multiviewLayout;
  61. this->drawLabel = drawLabel;
  62. this->drawSafeArea = drawSafeArea;
  63. multiviewScenes.clear();
  64. multiviewLabels.clear();
  65. struct obs_video_info ovi;
  66. obs_get_video_info(&ovi);
  67. uint32_t w = ovi.base_width;
  68. uint32_t h = ovi.base_height;
  69. fw = float(w);
  70. fh = float(h);
  71. ratio = fw / fh;
  72. struct obs_frontend_source_list scenes = {};
  73. obs_frontend_get_scenes(&scenes);
  74. multiviewLabels.emplace_back(
  75. CreateLabel(Str("StudioMode.Preview"), h / 2));
  76. multiviewLabels.emplace_back(
  77. CreateLabel(Str("StudioMode.Program"), h / 2));
  78. switch (multiviewLayout) {
  79. case MultiviewLayout::HORIZONTAL_TOP_18_SCENES:
  80. pvwprgCX = fw / 2;
  81. pvwprgCY = fh / 2;
  82. maxSrcs = 18;
  83. break;
  84. case MultiviewLayout::HORIZONTAL_TOP_24_SCENES:
  85. pvwprgCX = fw / 3;
  86. pvwprgCY = fh / 3;
  87. maxSrcs = 24;
  88. break;
  89. case MultiviewLayout::SCENES_ONLY_4_SCENES:
  90. pvwprgCX = fw / 2;
  91. pvwprgCY = fh / 2;
  92. maxSrcs = 4;
  93. break;
  94. case MultiviewLayout::SCENES_ONLY_9_SCENES:
  95. pvwprgCX = fw / 3;
  96. pvwprgCY = fh / 3;
  97. maxSrcs = 9;
  98. break;
  99. case MultiviewLayout::SCENES_ONLY_16_SCENES:
  100. pvwprgCX = fw / 4;
  101. pvwprgCY = fh / 4;
  102. maxSrcs = 16;
  103. break;
  104. case MultiviewLayout::SCENES_ONLY_25_SCENES:
  105. pvwprgCX = fw / 5;
  106. pvwprgCY = fh / 5;
  107. maxSrcs = 25;
  108. break;
  109. default:
  110. pvwprgCX = fw / 2;
  111. pvwprgCY = fh / 2;
  112. maxSrcs = 8;
  113. }
  114. ppiCX = pvwprgCX - thicknessx2;
  115. ppiCY = pvwprgCY - thicknessx2;
  116. ppiScaleX = (pvwprgCX - thicknessx2) / fw;
  117. ppiScaleY = (pvwprgCY - thicknessx2) / fh;
  118. switch (multiviewLayout) {
  119. case MultiviewLayout::HORIZONTAL_TOP_18_SCENES:
  120. scenesCX = pvwprgCX / 3;
  121. scenesCY = pvwprgCY / 3;
  122. break;
  123. case MultiviewLayout::SCENES_ONLY_4_SCENES:
  124. case MultiviewLayout::SCENES_ONLY_9_SCENES:
  125. case MultiviewLayout::SCENES_ONLY_16_SCENES:
  126. case MultiviewLayout::SCENES_ONLY_25_SCENES:
  127. scenesCX = pvwprgCX;
  128. scenesCY = pvwprgCY;
  129. break;
  130. default:
  131. scenesCX = pvwprgCX / 2;
  132. scenesCY = pvwprgCY / 2;
  133. }
  134. siCX = scenesCX - thicknessx2;
  135. siCY = scenesCY - thicknessx2;
  136. siScaleX = (scenesCX - thicknessx2) / fw;
  137. siScaleY = (scenesCY - thicknessx2) / fh;
  138. numSrcs = 0;
  139. size_t i = 0;
  140. while (i < scenes.sources.num && numSrcs < maxSrcs) {
  141. obs_source_t *src = scenes.sources.array[i++];
  142. OBSDataAutoRelease data = obs_source_get_private_settings(src);
  143. obs_data_set_default_bool(data, "show_in_multiview", true);
  144. if (!obs_data_get_bool(data, "show_in_multiview"))
  145. continue;
  146. // We have a displayable source.
  147. numSrcs++;
  148. multiviewScenes.emplace_back(OBSGetWeakRef(src));
  149. obs_source_inc_showing(src);
  150. multiviewLabels.emplace_back(
  151. CreateLabel(obs_source_get_name(src), h / 3));
  152. }
  153. obs_frontend_source_list_free(&scenes);
  154. }
  155. static inline uint32_t labelOffset(MultiviewLayout multiviewLayout,
  156. obs_source_t *label, uint32_t cx)
  157. {
  158. uint32_t w = obs_source_get_width(label);
  159. int n; // Twice of scale factor of preview and program scenes
  160. switch (multiviewLayout) {
  161. case MultiviewLayout::HORIZONTAL_TOP_24_SCENES:
  162. n = 6;
  163. break;
  164. case MultiviewLayout::SCENES_ONLY_25_SCENES:
  165. n = 10;
  166. break;
  167. case MultiviewLayout::SCENES_ONLY_16_SCENES:
  168. n = 8;
  169. break;
  170. case MultiviewLayout::SCENES_ONLY_9_SCENES:
  171. n = 6;
  172. break;
  173. case MultiviewLayout::SCENES_ONLY_4_SCENES:
  174. n = 4;
  175. break;
  176. default:
  177. n = 4;
  178. break;
  179. }
  180. w = uint32_t(w * ((1.0f) / n));
  181. return (cx / 2) - w;
  182. }
  183. void Multiview::Render(uint32_t cx, uint32_t cy)
  184. {
  185. OBSBasic *main = (OBSBasic *)obs_frontend_get_main_window();
  186. uint32_t targetCX, targetCY;
  187. int x, y;
  188. float scale;
  189. targetCX = (uint32_t)fw;
  190. targetCY = (uint32_t)fh;
  191. GetScaleAndCenterPos(targetCX, targetCY, cx, cy, x, y, scale);
  192. OBSSource previewSrc = main->GetCurrentSceneSource();
  193. OBSSource programSrc = main->GetProgramSource();
  194. bool studioMode = main->IsPreviewProgramMode();
  195. auto drawBox = [&](float cx, float cy, uint32_t colorVal) {
  196. gs_effect_t *solid = obs_get_base_effect(OBS_EFFECT_SOLID);
  197. gs_eparam_t *color =
  198. gs_effect_get_param_by_name(solid, "color");
  199. gs_effect_set_color(color, colorVal);
  200. while (gs_effect_loop(solid, "Solid"))
  201. gs_draw_sprite(nullptr, 0, (uint32_t)cx, (uint32_t)cy);
  202. };
  203. auto setRegion = [&](float bx, float by, float cx, float cy) {
  204. float vX = int(x + bx * scale);
  205. float vY = int(y + by * scale);
  206. float vCX = int(cx * scale);
  207. float vCY = int(cy * scale);
  208. float oL = bx;
  209. float oT = by;
  210. float oR = (bx + cx);
  211. float oB = (by + cy);
  212. startRegion(vX, vY, vCX, vCY, oL, oR, oT, oB);
  213. };
  214. auto calcBaseSource = [&](size_t i) {
  215. switch (multiviewLayout) {
  216. case MultiviewLayout::HORIZONTAL_TOP_18_SCENES:
  217. sourceX = (i % 6) * scenesCX;
  218. sourceY = pvwprgCY + (i / 6) * scenesCY;
  219. break;
  220. case MultiviewLayout::HORIZONTAL_TOP_24_SCENES:
  221. sourceX = (i % 6) * scenesCX;
  222. sourceY = pvwprgCY + (i / 6) * scenesCY;
  223. break;
  224. case MultiviewLayout::VERTICAL_LEFT_8_SCENES:
  225. sourceX = pvwprgCX;
  226. sourceY = (i / 2) * scenesCY;
  227. if (i % 2 != 0)
  228. sourceX += scenesCX;
  229. break;
  230. case MultiviewLayout::VERTICAL_RIGHT_8_SCENES:
  231. sourceX = 0;
  232. sourceY = (i / 2) * scenesCY;
  233. if (i % 2 != 0)
  234. sourceX = scenesCX;
  235. break;
  236. case MultiviewLayout::HORIZONTAL_BOTTOM_8_SCENES:
  237. if (i < 4) {
  238. sourceX = (float(i) * scenesCX);
  239. sourceY = 0;
  240. } else {
  241. sourceX = (float(i - 4) * scenesCX);
  242. sourceY = scenesCY;
  243. }
  244. break;
  245. case MultiviewLayout::SCENES_ONLY_4_SCENES:
  246. sourceX = (i % 2) * scenesCX;
  247. sourceY = (i / 2) * scenesCY;
  248. break;
  249. case MultiviewLayout::SCENES_ONLY_9_SCENES:
  250. sourceX = (i % 3) * scenesCX;
  251. sourceY = (i / 3) * scenesCY;
  252. break;
  253. case MultiviewLayout::SCENES_ONLY_16_SCENES:
  254. sourceX = (i % 4) * scenesCX;
  255. sourceY = (i / 4) * scenesCY;
  256. break;
  257. case MultiviewLayout::SCENES_ONLY_25_SCENES:
  258. sourceX = (i % 5) * scenesCX;
  259. sourceY = (i / 5) * scenesCY;
  260. break;
  261. default: // MultiviewLayout::HORIZONTAL_TOP_8_SCENES:
  262. if (i < 4) {
  263. sourceX = (float(i) * scenesCX);
  264. sourceY = pvwprgCY;
  265. } else {
  266. sourceX = (float(i - 4) * scenesCX);
  267. sourceY = pvwprgCY + scenesCY;
  268. }
  269. }
  270. siX = sourceX + thickness;
  271. siY = sourceY + thickness;
  272. };
  273. auto calcPreviewProgram = [&](bool program) {
  274. switch (multiviewLayout) {
  275. case MultiviewLayout::HORIZONTAL_TOP_24_SCENES:
  276. sourceX = thickness + pvwprgCX / 2;
  277. sourceY = thickness;
  278. labelX = offset + pvwprgCX / 2;
  279. labelY = pvwprgCY;
  280. if (program) {
  281. sourceX += pvwprgCX;
  282. labelX += pvwprgCX;
  283. }
  284. break;
  285. case MultiviewLayout::VERTICAL_LEFT_8_SCENES:
  286. sourceX = thickness;
  287. sourceY = pvwprgCY + thickness;
  288. labelX = offset;
  289. labelY = pvwprgCY * 2;
  290. if (program) {
  291. sourceY = thickness;
  292. labelY = pvwprgCY;
  293. }
  294. break;
  295. case MultiviewLayout::VERTICAL_RIGHT_8_SCENES:
  296. sourceX = pvwprgCX + thickness;
  297. sourceY = pvwprgCY + thickness;
  298. labelX = pvwprgCX + offset;
  299. labelY = pvwprgCY * 2;
  300. if (program) {
  301. sourceY = thickness;
  302. labelY = pvwprgCY;
  303. }
  304. break;
  305. case MultiviewLayout::HORIZONTAL_BOTTOM_8_SCENES:
  306. sourceX = thickness;
  307. sourceY = pvwprgCY + thickness;
  308. labelX = offset;
  309. labelY = pvwprgCY * 2;
  310. if (program) {
  311. sourceX += pvwprgCX;
  312. labelX += pvwprgCX;
  313. }
  314. break;
  315. case MultiviewLayout::SCENES_ONLY_4_SCENES:
  316. case MultiviewLayout::SCENES_ONLY_9_SCENES:
  317. case MultiviewLayout::SCENES_ONLY_16_SCENES:
  318. sourceX = thickness;
  319. sourceY = thickness;
  320. labelX = offset;
  321. break;
  322. default: // MultiviewLayout::HORIZONTAL_TOP_8_SCENES and 18_SCENES
  323. sourceX = thickness;
  324. sourceY = thickness;
  325. labelX = offset;
  326. labelY = pvwprgCY;
  327. if (program) {
  328. sourceX += pvwprgCX;
  329. labelX += pvwprgCX;
  330. }
  331. }
  332. };
  333. auto paintAreaWithColor = [&](float tx, float ty, float cx, float cy,
  334. uint32_t color) {
  335. gs_matrix_push();
  336. gs_matrix_translate3f(tx, ty, 0.0f);
  337. drawBox(cx, cy, color);
  338. gs_matrix_pop();
  339. };
  340. // Define the whole usable region for the multiview
  341. startRegion(x, y, targetCX * scale, targetCY * scale, 0.0f, fw, 0.0f,
  342. fh);
  343. // Change the background color to highlight all sources
  344. drawBox(fw, fh, outerColor);
  345. /* ----------------------------- */
  346. /* draw sources */
  347. for (size_t i = 0; i < maxSrcs; i++) {
  348. // Handle all the offsets
  349. calcBaseSource(i);
  350. if (i >= numSrcs) {
  351. // Just paint the background and continue
  352. paintAreaWithColor(sourceX, sourceY, scenesCX, scenesCY,
  353. outerColor);
  354. paintAreaWithColor(siX, siY, siCX, siCY,
  355. backgroundColor);
  356. continue;
  357. }
  358. OBSSource src = OBSGetStrongRef(multiviewScenes[i]);
  359. // We have a source. Now chose the proper highlight color
  360. uint32_t colorVal = outerColor;
  361. if (src == programSrc)
  362. colorVal = programColor;
  363. else if (src == previewSrc)
  364. colorVal = studioMode ? previewColor : programColor;
  365. // Paint the background
  366. paintAreaWithColor(sourceX, sourceY, scenesCX, scenesCY,
  367. colorVal);
  368. paintAreaWithColor(siX, siY, siCX, siCY, backgroundColor);
  369. /* ----------- */
  370. // Render the source
  371. gs_matrix_push();
  372. gs_matrix_translate3f(siX, siY, 0.0f);
  373. gs_matrix_scale3f(siScaleX, siScaleY, 1.0f);
  374. setRegion(siX, siY, siCX, siCY);
  375. obs_source_video_render(src);
  376. endRegion();
  377. gs_matrix_pop();
  378. /* ----------- */
  379. // Render the label
  380. if (!drawLabel)
  381. continue;
  382. obs_source *label = multiviewLabels[i + 2];
  383. if (!label)
  384. continue;
  385. offset = labelOffset(multiviewLayout, label, scenesCX);
  386. gs_matrix_push();
  387. gs_matrix_translate3f(
  388. sourceX + offset,
  389. sourceY + scenesCY -
  390. (obs_source_get_height(label) * ppiScaleY) -
  391. (thickness * 3),
  392. 0.0f);
  393. gs_matrix_scale3f(ppiScaleX, ppiScaleY, 1.0f);
  394. drawBox(obs_source_get_width(label),
  395. obs_source_get_height(label) + thicknessx2, labelColor);
  396. gs_matrix_translate3f(0, thickness, 0.0f);
  397. obs_source_video_render(label);
  398. gs_matrix_pop();
  399. }
  400. if (multiviewLayout == MultiviewLayout::SCENES_ONLY_4_SCENES ||
  401. multiviewLayout == MultiviewLayout::SCENES_ONLY_9_SCENES ||
  402. multiviewLayout == MultiviewLayout::SCENES_ONLY_16_SCENES ||
  403. multiviewLayout == MultiviewLayout::SCENES_ONLY_25_SCENES) {
  404. endRegion();
  405. return;
  406. }
  407. /* ----------------------------- */
  408. /* draw preview */
  409. obs_source_t *previewLabel = multiviewLabels[0];
  410. offset = labelOffset(multiviewLayout, previewLabel, pvwprgCX);
  411. calcPreviewProgram(false);
  412. // Paint the background
  413. paintAreaWithColor(sourceX, sourceY, ppiCX, ppiCY, backgroundColor);
  414. // Scale and Draw the preview
  415. gs_matrix_push();
  416. gs_matrix_translate3f(sourceX, sourceY, 0.0f);
  417. gs_matrix_scale3f(ppiScaleX, ppiScaleY, 1.0f);
  418. setRegion(sourceX, sourceY, ppiCX, ppiCY);
  419. if (studioMode)
  420. obs_source_video_render(previewSrc);
  421. else
  422. obs_render_main_texture();
  423. if (drawSafeArea) {
  424. RenderSafeAreas(actionSafeMargin, targetCX, targetCY);
  425. RenderSafeAreas(graphicsSafeMargin, targetCX, targetCY);
  426. RenderSafeAreas(fourByThreeSafeMargin, targetCX, targetCY);
  427. RenderSafeAreas(leftLine, targetCX, targetCY);
  428. RenderSafeAreas(topLine, targetCX, targetCY);
  429. RenderSafeAreas(rightLine, targetCX, targetCY);
  430. }
  431. endRegion();
  432. gs_matrix_pop();
  433. /* ----------- */
  434. // Draw the Label
  435. if (drawLabel) {
  436. gs_matrix_push();
  437. gs_matrix_translate3f(
  438. labelX,
  439. labelY -
  440. (obs_source_get_height(previewLabel) *
  441. ppiScaleY) -
  442. (thickness * 3),
  443. 0.0f);
  444. gs_matrix_scale3f(ppiScaleX, ppiScaleY, 1.0f);
  445. drawBox(obs_source_get_width(previewLabel),
  446. obs_source_get_height(previewLabel) + thicknessx2,
  447. labelColor);
  448. gs_matrix_translate3f(0, thickness, 0.0f);
  449. obs_source_video_render(previewLabel);
  450. gs_matrix_pop();
  451. }
  452. /* ----------------------------- */
  453. /* draw program */
  454. obs_source_t *programLabel = multiviewLabels[1];
  455. offset = labelOffset(multiviewLayout, programLabel, pvwprgCX);
  456. calcPreviewProgram(true);
  457. paintAreaWithColor(sourceX, sourceY, ppiCX, ppiCY, backgroundColor);
  458. // Scale and Draw the program
  459. gs_matrix_push();
  460. gs_matrix_translate3f(sourceX, sourceY, 0.0f);
  461. gs_matrix_scale3f(ppiScaleX, ppiScaleY, 1.0f);
  462. setRegion(sourceX, sourceY, ppiCX, ppiCY);
  463. obs_render_main_texture();
  464. endRegion();
  465. gs_matrix_pop();
  466. /* ----------- */
  467. // Draw the Label
  468. if (drawLabel) {
  469. gs_matrix_push();
  470. gs_matrix_translate3f(
  471. labelX,
  472. labelY -
  473. (obs_source_get_height(programLabel) *
  474. ppiScaleY) -
  475. (thickness * 3),
  476. 0.0f);
  477. gs_matrix_scale3f(ppiScaleX, ppiScaleY, 1.0f);
  478. drawBox(obs_source_get_width(programLabel),
  479. obs_source_get_height(programLabel) + thicknessx2,
  480. labelColor);
  481. gs_matrix_translate3f(0, thickness, 0.0f);
  482. obs_source_video_render(programLabel);
  483. gs_matrix_pop();
  484. }
  485. // Region for future usage with additional info.
  486. if (multiviewLayout == MultiviewLayout::HORIZONTAL_TOP_24_SCENES) {
  487. // Just paint the background for now
  488. paintAreaWithColor(thickness, thickness, siCX,
  489. siCY * 2 + thicknessx2, backgroundColor);
  490. paintAreaWithColor(thickness + 2.5 * (thicknessx2 + ppiCX),
  491. thickness, siCX, siCY * 2 + thicknessx2,
  492. backgroundColor);
  493. }
  494. endRegion();
  495. }
  496. OBSSource Multiview::GetSourceByPosition(int x, int y)
  497. {
  498. int pos = -1;
  499. QWidget *rec = QApplication::activeWindow();
  500. if (!rec)
  501. return nullptr;
  502. int cx = rec->width();
  503. int cy = rec->height();
  504. int minX = 0;
  505. int minY = 0;
  506. int maxX = cx;
  507. int maxY = cy;
  508. switch (multiviewLayout) {
  509. case MultiviewLayout::HORIZONTAL_TOP_18_SCENES:
  510. if (float(cx) / float(cy) > ratio) {
  511. int validX = cy * ratio;
  512. minX = (cx / 2) - (validX / 2);
  513. maxX = (cx / 2) + (validX / 2);
  514. } else {
  515. int validY = cx / ratio;
  516. maxY = (cy / 2) + (validY / 2);
  517. }
  518. minY = cy / 2;
  519. if (x < minX || x > maxX || y < minY || y > maxY)
  520. break;
  521. pos = (x - minX) / ((maxX - minX) / 6);
  522. pos += ((y - minY) / ((maxY - minY) / 3)) * 6;
  523. break;
  524. case MultiviewLayout::HORIZONTAL_TOP_24_SCENES:
  525. if (float(cx) / float(cy) > ratio) {
  526. int validX = cy * ratio;
  527. minX = (cx / 2) - (validX / 2);
  528. maxX = (cx / 2) + (validX / 2);
  529. minY = cy / 3;
  530. } else {
  531. int validY = cx / ratio;
  532. maxY = (cy / 2) + (validY / 2);
  533. minY = (cy / 2) - (validY / 6);
  534. }
  535. if (x < minX || x > maxX || y < minY || y > maxY)
  536. break;
  537. pos = (x - minX) / ((maxX - minX) / 6);
  538. pos += ((y - minY) / ((maxY - minY) / 4)) * 6;
  539. break;
  540. case MultiviewLayout::VERTICAL_LEFT_8_SCENES:
  541. if (float(cx) / float(cy) > ratio) {
  542. int validX = cy * ratio;
  543. maxX = (cx / 2) + (validX / 2);
  544. } else {
  545. int validY = cx / ratio;
  546. minY = (cy / 2) - (validY / 2);
  547. maxY = (cy / 2) + (validY / 2);
  548. }
  549. minX = cx / 2;
  550. if (x < minX || x > maxX || y < minY || y > maxY)
  551. break;
  552. pos = 2 * ((y - minY) / ((maxY - minY) / 4));
  553. if (x > minX + ((maxX - minX) / 2))
  554. pos++;
  555. break;
  556. case MultiviewLayout::VERTICAL_RIGHT_8_SCENES:
  557. if (float(cx) / float(cy) > ratio) {
  558. int validX = cy * ratio;
  559. minX = (cx / 2) - (validX / 2);
  560. } else {
  561. int validY = cx / ratio;
  562. minY = (cy / 2) - (validY / 2);
  563. maxY = (cy / 2) + (validY / 2);
  564. }
  565. maxX = (cx / 2);
  566. if (x < minX || x > maxX || y < minY || y > maxY)
  567. break;
  568. pos = 2 * ((y - minY) / ((maxY - minY) / 4));
  569. if (x > minX + ((maxX - minX) / 2))
  570. pos++;
  571. break;
  572. case MultiviewLayout::HORIZONTAL_BOTTOM_8_SCENES:
  573. if (float(cx) / float(cy) > ratio) {
  574. int validX = cy * ratio;
  575. minX = (cx / 2) - (validX / 2);
  576. maxX = (cx / 2) + (validX / 2);
  577. } else {
  578. int validY = cx / ratio;
  579. minY = (cy / 2) - (validY / 2);
  580. }
  581. maxY = (cy / 2);
  582. if (x < minX || x > maxX || y < minY || y > maxY)
  583. break;
  584. pos = (x - minX) / ((maxX - minX) / 4);
  585. if (y > minY + ((maxY - minY) / 2))
  586. pos += 4;
  587. break;
  588. case MultiviewLayout::SCENES_ONLY_4_SCENES:
  589. if (float(cx) / float(cy) > ratio) {
  590. int validX = cy * ratio;
  591. minX = (cx / 2) - (validX / 2);
  592. maxX = (cx / 2) + (validX / 2);
  593. } else {
  594. int validY = cx / ratio;
  595. maxY = (cy / 2) + (validY / 2);
  596. minY = (cy / 2) - (validY / 2);
  597. }
  598. if (x < minX || x > maxX || y < minY || y > maxY)
  599. break;
  600. pos = (x - minX) / ((maxX - minX) / 2);
  601. pos += ((y - minY) / ((maxY - minY) / 2)) * 2;
  602. break;
  603. case MultiviewLayout::SCENES_ONLY_9_SCENES:
  604. if (float(cx) / float(cy) > ratio) {
  605. int validX = cy * ratio;
  606. minX = (cx / 2) - (validX / 2);
  607. maxX = (cx / 2) + (validX / 2);
  608. } else {
  609. int validY = cx / ratio;
  610. maxY = (cy / 2) + (validY / 2);
  611. minY = (cy / 2) - (validY / 2);
  612. }
  613. if (x < minX || x > maxX || y < minY || y > maxY)
  614. break;
  615. pos = (x - minX) / ((maxX - minX) / 3);
  616. pos += ((y - minY) / ((maxY - minY) / 3)) * 3;
  617. break;
  618. case MultiviewLayout::SCENES_ONLY_16_SCENES:
  619. if (float(cx) / float(cy) > ratio) {
  620. int validX = cy * ratio;
  621. minX = (cx / 2) - (validX / 2);
  622. maxX = (cx / 2) + (validX / 2);
  623. } else {
  624. int validY = cx / ratio;
  625. maxY = (cy / 2) + (validY / 2);
  626. minY = (cy / 2) - (validY / 2);
  627. }
  628. if (x < minX || x > maxX || y < minY || y > maxY)
  629. break;
  630. pos = (x - minX) / ((maxX - minX) / 4);
  631. pos += ((y - minY) / ((maxY - minY) / 4)) * 4;
  632. break;
  633. case MultiviewLayout::SCENES_ONLY_25_SCENES:
  634. if (float(cx) / float(cy) > ratio) {
  635. int validX = cy * ratio;
  636. minX = (cx / 2) - (validX / 2);
  637. maxX = (cx / 2) + (validX / 2);
  638. } else {
  639. int validY = cx / ratio;
  640. maxY = (cy / 2) + (validY / 2);
  641. minY = (cy / 2) - (validY / 2);
  642. }
  643. if (x < minX || x > maxX || y < minY || y > maxY)
  644. break;
  645. pos = (x - minX) / ((maxX - minX) / 5);
  646. pos += ((y - minY) / ((maxY - minY) / 5)) * 5;
  647. break;
  648. default: // MultiviewLayout::HORIZONTAL_TOP_8_SCENES
  649. if (float(cx) / float(cy) > ratio) {
  650. int validX = cy * ratio;
  651. minX = (cx / 2) - (validX / 2);
  652. maxX = (cx / 2) + (validX / 2);
  653. } else {
  654. int validY = cx / ratio;
  655. maxY = (cy / 2) + (validY / 2);
  656. }
  657. minY = (cy / 2);
  658. if (x < minX || x > maxX || y < minY || y > maxY)
  659. break;
  660. pos = (x - minX) / ((maxX - minX) / 4);
  661. if (y > minY + ((maxY - minY) / 2))
  662. pos += 4;
  663. }
  664. if (pos < 0 || pos >= (int)numSrcs)
  665. return nullptr;
  666. return OBSGetStrongRef(multiviewScenes[pos]);
  667. }