1
0

multiview.hpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #pragma once
  2. #include <obs.hpp>
  3. #include <vector>
  4. enum class MultiviewLayout : uint8_t {
  5. HORIZONTAL_TOP_8_SCENES = 0,
  6. HORIZONTAL_BOTTOM_8_SCENES = 1,
  7. VERTICAL_LEFT_8_SCENES = 2,
  8. VERTICAL_RIGHT_8_SCENES = 3,
  9. HORIZONTAL_TOP_24_SCENES = 4,
  10. HORIZONTAL_TOP_18_SCENES = 5,
  11. SCENES_ONLY_4_SCENES = 6,
  12. SCENES_ONLY_9_SCENES = 7,
  13. SCENES_ONLY_16_SCENES = 8,
  14. SCENES_ONLY_25_SCENES = 9,
  15. };
  16. class Multiview {
  17. public:
  18. Multiview();
  19. ~Multiview();
  20. void Update(MultiviewLayout multiviewLayout, bool drawLabel,
  21. bool drawSafeArea);
  22. void Render(uint32_t cx, uint32_t cy);
  23. OBSSource GetSourceByPosition(int x, int y);
  24. private:
  25. bool drawLabel, drawSafeArea;
  26. MultiviewLayout multiviewLayout;
  27. size_t maxSrcs, numSrcs;
  28. gs_vertbuffer_t *actionSafeMargin = nullptr;
  29. gs_vertbuffer_t *graphicsSafeMargin = nullptr;
  30. gs_vertbuffer_t *fourByThreeSafeMargin = nullptr;
  31. gs_vertbuffer_t *leftLine = nullptr;
  32. gs_vertbuffer_t *topLine = nullptr;
  33. gs_vertbuffer_t *rightLine = nullptr;
  34. std::vector<OBSWeakSource> multiviewScenes;
  35. std::vector<OBSSource> multiviewLabels;
  36. // Multiview position helpers
  37. float thickness = 4;
  38. float offset, thicknessx2 = thickness * 2, pvwprgCX, pvwprgCY, sourceX,
  39. sourceY, labelX, labelY, scenesCX, scenesCY, ppiCX, ppiCY,
  40. siX, siY, siCX, siCY, ppiScaleX, ppiScaleY, siScaleX,
  41. siScaleY, fw, fh, ratio;
  42. // argb colors
  43. static const uint32_t outerColor = 0xFFD0D0D0;
  44. static const uint32_t labelColor = 0xD91F1F1F;
  45. static const uint32_t backgroundColor = 0xFF000000;
  46. static const uint32_t previewColor = 0xFF00D000;
  47. static const uint32_t programColor = 0xFFD00000;
  48. };
  49. static inline void startRegion(int vX, int vY, int vCX, int vCY, float oL,
  50. float oR, float oT, float oB)
  51. {
  52. gs_projection_push();
  53. gs_viewport_push();
  54. gs_set_viewport(vX, vY, vCX, vCY);
  55. gs_ortho(oL, oR, oT, oB, -100.0f, 100.0f);
  56. }
  57. static inline void endRegion()
  58. {
  59. gs_viewport_pop();
  60. gs_projection_pop();
  61. }