Multiview.hpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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, bool drawSafeArea);
  21. void Render(uint32_t cx, uint32_t cy);
  22. OBSSource GetSourceByPosition(int x, int y);
  23. private:
  24. bool drawLabel, drawSafeArea;
  25. MultiviewLayout multiviewLayout;
  26. size_t maxSrcs, numSrcs;
  27. gs_vertbuffer_t *actionSafeMargin = nullptr;
  28. gs_vertbuffer_t *graphicsSafeMargin = nullptr;
  29. gs_vertbuffer_t *fourByThreeSafeMargin = nullptr;
  30. gs_vertbuffer_t *leftLine = nullptr;
  31. gs_vertbuffer_t *topLine = nullptr;
  32. gs_vertbuffer_t *rightLine = nullptr;
  33. std::vector<OBSWeakSource> multiviewScenes;
  34. std::vector<OBSSource> multiviewLabels;
  35. // Multiview position helpers
  36. float thickness = 6;
  37. float offset, thicknessx2 = thickness * 2, pvwprgCX, pvwprgCY, sourceX, sourceY, labelX, labelY, scenesCX,
  38. scenesCY, ppiCX, ppiCY, siX, siY, siCX, siCY, ppiScaleX, ppiScaleY, siScaleX, siScaleY, fw, fh,
  39. ratio;
  40. // argb colors
  41. static const uint32_t outerColor = 0xFF999999;
  42. static const uint32_t labelColor = 0x33000000;
  43. static const uint32_t backgroundColor = 0xFF000000;
  44. static const uint32_t previewColor = 0xFF00D000;
  45. static const uint32_t programColor = 0xFFD00000;
  46. };
  47. static inline void startRegion(int vX, int vY, int vCX, int vCY, float oL, float oR, float oT, float oB)
  48. {
  49. gs_projection_push();
  50. gs_viewport_push();
  51. gs_set_viewport(vX, vY, vCX, vCY);
  52. gs_ortho(oL, oR, oT, oB, -100.0f, 100.0f);
  53. }
  54. static inline void endRegion()
  55. {
  56. gs_viewport_pop();
  57. gs_projection_pop();
  58. }