window-projector.hpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #pragma once
  2. #include <obs.hpp>
  3. #include "qt-display.hpp"
  4. enum class ProjectorType {
  5. Source,
  6. Scene,
  7. Preview,
  8. StudioProgram,
  9. Multiview,
  10. };
  11. class QMouseEvent;
  12. enum class MultiviewLayout : uint8_t {
  13. HORIZONTAL_TOP_8_SCENES = 0,
  14. HORIZONTAL_BOTTOM_8_SCENES = 1,
  15. VERTICAL_LEFT_8_SCENES = 2,
  16. VERTICAL_RIGHT_8_SCENES = 3,
  17. HORIZONTAL_TOP_24_SCENES = 4,
  18. HORIZONTAL_TOP_18_SCENES = 5,
  19. };
  20. class OBSProjector : public OBSQTDisplay {
  21. Q_OBJECT
  22. private:
  23. OBSSource source;
  24. OBSSignal removedSignal;
  25. static void OBSRenderMultiview(void *data, uint32_t cx, uint32_t cy);
  26. static void OBSRender(void *data, uint32_t cx, uint32_t cy);
  27. static void OBSSourceRemoved(void *data, calldata_t *params);
  28. void mousePressEvent(QMouseEvent *event) override;
  29. void mouseDoubleClickEvent(QMouseEvent *event) override;
  30. void closeEvent(QCloseEvent *event) override;
  31. bool isAlwaysOnTop;
  32. bool isAlwaysOnTopOverridden = false;
  33. int savedMonitor = -1;
  34. ProjectorType type = ProjectorType::Source;
  35. std::vector<OBSWeakSource> multiviewScenes;
  36. std::vector<OBSSource> multiviewLabels;
  37. gs_vertbuffer_t *actionSafeMargin = nullptr;
  38. gs_vertbuffer_t *graphicsSafeMargin = nullptr;
  39. gs_vertbuffer_t *fourByThreeSafeMargin = nullptr;
  40. gs_vertbuffer_t *leftLine = nullptr;
  41. gs_vertbuffer_t *topLine = nullptr;
  42. gs_vertbuffer_t *rightLine = nullptr;
  43. gs_effect_t *solid = nullptr;
  44. gs_eparam_t *color = nullptr;
  45. // Multiview position helpers
  46. float thickness = 4;
  47. float offset, thicknessx2 = thickness * 2, pvwprgCX, pvwprgCY, sourceX,
  48. sourceY, labelX, labelY, scenesCX, scenesCY, ppiCX, ppiCY,
  49. siX, siY, siCX, siCY, ppiScaleX, ppiScaleY, siScaleX,
  50. siScaleY, fw, fh, ratio;
  51. float lineLength = 0.1f;
  52. // Rec. ITU-R BT.1848-1 / EBU R 95
  53. float actionSafePercentage = 0.035f; // 3.5%
  54. float graphicsSafePercentage = 0.05f; // 5.0%
  55. float fourByThreeSafePercentage = 0.1625f; // 16.25%
  56. bool ready = false;
  57. // argb colors
  58. static const uint32_t outerColor = 0xFFD0D0D0;
  59. static const uint32_t labelColor = 0xD91F1F1F;
  60. static const uint32_t backgroundColor = 0xFF000000;
  61. static const uint32_t previewColor = 0xFF00D000;
  62. static const uint32_t programColor = 0xFFD00000;
  63. void UpdateMultiview();
  64. void UpdateProjectorTitle(QString name);
  65. QRect prevGeometry;
  66. void SetMonitor(int monitor);
  67. QScreen *screen = nullptr;
  68. private slots:
  69. void EscapeTriggered();
  70. void OpenFullScreenProjector();
  71. void ResizeToContent();
  72. void OpenWindowedProjector();
  73. void AlwaysOnTopToggled(bool alwaysOnTop);
  74. void ScreenRemoved(QScreen *screen_);
  75. public:
  76. OBSProjector(QWidget *widget, obs_source_t *source_, int monitor,
  77. ProjectorType type_);
  78. ~OBSProjector();
  79. OBSSource GetSource();
  80. ProjectorType GetProjectorType();
  81. int GetMonitor();
  82. static void UpdateMultiviewProjectors();
  83. void RenameProjector(QString oldName, QString newName);
  84. void SetHideCursor();
  85. bool IsAlwaysOnTop() const;
  86. bool IsAlwaysOnTopOverridden() const;
  87. void SetIsAlwaysOnTop(bool isAlwaysOnTop, bool isOverridden);
  88. };