2016-02-23 23:16:51 +00:00
|
|
|
#include <QAction>
|
2017-04-19 19:54:15 +00:00
|
|
|
#include <QGuiApplication>
|
2016-02-23 23:16:51 +00:00
|
|
|
#include <QMouseEvent>
|
|
|
|
#include <QMenu>
|
2017-04-19 19:54:15 +00:00
|
|
|
#include <QScreen>
|
2018-12-16 16:14:58 +00:00
|
|
|
#include "obs-app.hpp"
|
|
|
|
#include "window-basic-main.hpp"
|
2016-02-23 23:16:51 +00:00
|
|
|
#include "display-helpers.hpp"
|
|
|
|
#include "qt-wrappers.hpp"
|
|
|
|
#include "platform.hpp"
|
2018-02-19 19:54:37 +00:00
|
|
|
|
|
|
|
static QList<OBSProjector *> multiviewProjectors;
|
2020-10-01 20:15:25 +00:00
|
|
|
static QList<OBSProjector *> allProjectors;
|
|
|
|
|
2018-12-16 16:14:58 +00:00
|
|
|
static bool updatingMultiview = false, drawLabel, drawSafeArea, mouseSwitching,
|
2019-09-22 21:19:10 +00:00
|
|
|
transitionOnDoubleClick;
|
2018-12-16 16:14:58 +00:00
|
|
|
static MultiviewLayout multiviewLayout;
|
|
|
|
static size_t maxSrcs, numSrcs;
|
2016-02-23 23:16:51 +00:00
|
|
|
|
2018-12-16 16:14:58 +00:00
|
|
|
OBSProjector::OBSProjector(QWidget *widget, obs_source_t *source_, int monitor,
|
2020-03-25 08:07:22 +00:00
|
|
|
ProjectorType type_)
|
2019-09-22 21:19:10 +00:00
|
|
|
: OBSQTDisplay(widget, Qt::Window),
|
|
|
|
source(source_),
|
|
|
|
removedSignal(obs_source_get_signal_handler(source), "remove",
|
|
|
|
OBSSourceRemoved, this)
|
2016-02-23 23:16:51 +00:00
|
|
|
{
|
2020-10-01 20:15:25 +00:00
|
|
|
isAlwaysOnTop = config_get_bool(GetGlobalConfig(), "BasicWindow",
|
|
|
|
"ProjectorAlwaysOnTop");
|
|
|
|
|
|
|
|
if (isAlwaysOnTop)
|
|
|
|
setWindowFlags(Qt::WindowStaysOnTopHint);
|
|
|
|
|
2019-09-22 21:19:10 +00:00
|
|
|
type = type_;
|
2020-12-22 17:32:50 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
setWindowIcon(
|
|
|
|
QIcon::fromTheme("obs", QIcon(":/res/images/obs_256x256.png")));
|
|
|
|
#else
|
2020-03-25 08:07:22 +00:00
|
|
|
setWindowIcon(QIcon::fromTheme("obs", QIcon(":/res/images/obs.png")));
|
2020-12-22 17:32:50 +00:00
|
|
|
#endif
|
2018-12-16 16:14:58 +00:00
|
|
|
|
2020-03-25 08:07:22 +00:00
|
|
|
if (monitor == -1)
|
2018-12-16 16:14:58 +00:00
|
|
|
resize(480, 270);
|
2020-03-25 08:07:22 +00:00
|
|
|
else
|
|
|
|
SetMonitor(monitor);
|
2018-12-16 16:14:58 +00:00
|
|
|
|
2020-03-25 08:07:22 +00:00
|
|
|
UpdateProjectorTitle(QT_UTF8(obs_source_get_name(source)));
|
2018-12-16 16:14:58 +00:00
|
|
|
|
2020-03-25 08:07:22 +00:00
|
|
|
QAction *action = new QAction(this);
|
|
|
|
action->setShortcut(Qt::Key_Escape);
|
|
|
|
addAction(action);
|
|
|
|
connect(action, SIGNAL(triggered()), this, SLOT(EscapeTriggered()));
|
2017-06-29 19:01:10 +00:00
|
|
|
|
2016-02-23 23:16:51 +00:00
|
|
|
setAttribute(Qt::WA_DeleteOnClose, true);
|
|
|
|
|
2017-04-19 19:54:15 +00:00
|
|
|
//disable application quit when last window closed
|
|
|
|
setAttribute(Qt::WA_QuitOnClose, false);
|
|
|
|
|
2016-02-23 23:16:51 +00:00
|
|
|
installEventFilter(CreateShortcutFilter());
|
|
|
|
|
2019-09-22 21:19:10 +00:00
|
|
|
auto addDrawCallback = [this]() {
|
2018-02-19 19:54:37 +00:00
|
|
|
bool isMultiview = type == ProjectorType::Multiview;
|
2019-09-22 21:19:10 +00:00
|
|
|
obs_display_add_draw_callback(
|
|
|
|
GetDisplay(),
|
|
|
|
isMultiview ? OBSRenderMultiview : OBSRender, this);
|
|
|
|
obs_display_set_background_color(GetDisplay(), 0x000000);
|
2016-02-23 23:16:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
connect(this, &OBSQTDisplay::DisplayCreated, addDrawCallback);
|
2020-10-01 20:15:25 +00:00
|
|
|
connect(App(), &QGuiApplication::screenRemoved, this,
|
|
|
|
&OBSProjector::ScreenRemoved);
|
2016-02-23 23:16:51 +00:00
|
|
|
|
2018-12-16 16:14:58 +00:00
|
|
|
if (type == ProjectorType::Multiview) {
|
|
|
|
obs_enter_graphics();
|
|
|
|
|
|
|
|
// All essential action should be placed inside this area
|
|
|
|
gs_render_start(true);
|
|
|
|
gs_vertex2f(actionSafePercentage, actionSafePercentage);
|
|
|
|
gs_vertex2f(actionSafePercentage, 1 - actionSafePercentage);
|
|
|
|
gs_vertex2f(1 - actionSafePercentage, 1 - actionSafePercentage);
|
|
|
|
gs_vertex2f(1 - actionSafePercentage, actionSafePercentage);
|
|
|
|
gs_vertex2f(actionSafePercentage, actionSafePercentage);
|
|
|
|
actionSafeMargin = gs_render_save();
|
|
|
|
|
|
|
|
// All graphics should be placed inside this area
|
|
|
|
gs_render_start(true);
|
|
|
|
gs_vertex2f(graphicsSafePercentage, graphicsSafePercentage);
|
|
|
|
gs_vertex2f(graphicsSafePercentage, 1 - graphicsSafePercentage);
|
|
|
|
gs_vertex2f(1 - graphicsSafePercentage,
|
2019-09-22 21:19:10 +00:00
|
|
|
1 - graphicsSafePercentage);
|
2018-12-16 16:14:58 +00:00
|
|
|
gs_vertex2f(1 - graphicsSafePercentage, graphicsSafePercentage);
|
|
|
|
gs_vertex2f(graphicsSafePercentage, graphicsSafePercentage);
|
|
|
|
graphicsSafeMargin = gs_render_save();
|
|
|
|
|
|
|
|
// 4:3 safe area for widescreen
|
|
|
|
gs_render_start(true);
|
|
|
|
gs_vertex2f(fourByThreeSafePercentage, graphicsSafePercentage);
|
|
|
|
gs_vertex2f(1 - fourByThreeSafePercentage,
|
2019-09-22 21:19:10 +00:00
|
|
|
graphicsSafePercentage);
|
|
|
|
gs_vertex2f(1 - fourByThreeSafePercentage,
|
|
|
|
1 - graphicsSafePercentage);
|
2018-12-16 16:14:58 +00:00
|
|
|
gs_vertex2f(fourByThreeSafePercentage,
|
2019-09-22 21:19:10 +00:00
|
|
|
1 - graphicsSafePercentage);
|
2018-12-16 16:14:58 +00:00
|
|
|
gs_vertex2f(fourByThreeSafePercentage, graphicsSafePercentage);
|
|
|
|
fourByThreeSafeMargin = gs_render_save();
|
|
|
|
|
|
|
|
gs_render_start(true);
|
|
|
|
gs_vertex2f(0.0f, 0.5f);
|
|
|
|
gs_vertex2f(lineLength, 0.5f);
|
|
|
|
leftLine = gs_render_save();
|
|
|
|
|
|
|
|
gs_render_start(true);
|
|
|
|
gs_vertex2f(0.5f, 0.0f);
|
|
|
|
gs_vertex2f(0.5f, lineLength);
|
|
|
|
topLine = gs_render_save();
|
|
|
|
|
|
|
|
gs_render_start(true);
|
|
|
|
gs_vertex2f(1.0f, 0.5f);
|
|
|
|
gs_vertex2f(1 - lineLength, 0.5f);
|
|
|
|
rightLine = gs_render_save();
|
|
|
|
obs_leave_graphics();
|
|
|
|
|
|
|
|
solid = obs_get_base_effect(OBS_EFFECT_SOLID);
|
|
|
|
color = gs_effect_get_param_by_name(solid, "color");
|
|
|
|
|
|
|
|
UpdateMultiview();
|
|
|
|
|
|
|
|
multiviewProjectors.push_back(this);
|
|
|
|
}
|
|
|
|
|
2016-02-23 23:16:51 +00:00
|
|
|
App()->IncrementSleepInhibition();
|
2018-12-16 16:14:58 +00:00
|
|
|
|
|
|
|
if (source)
|
|
|
|
obs_source_inc_showing(source);
|
|
|
|
|
2020-10-01 20:15:25 +00:00
|
|
|
allProjectors.push_back(this);
|
|
|
|
|
2018-12-16 16:14:58 +00:00
|
|
|
ready = true;
|
|
|
|
|
|
|
|
show();
|
|
|
|
|
|
|
|
// We need it here to allow keyboard input in X11 to listen to Escape
|
2020-03-25 08:07:22 +00:00
|
|
|
activateWindow();
|
2016-02-23 23:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
OBSProjector::~OBSProjector()
|
|
|
|
{
|
2018-02-19 19:54:37 +00:00
|
|
|
bool isMultiview = type == ProjectorType::Multiview;
|
2019-09-22 21:19:10 +00:00
|
|
|
obs_display_remove_draw_callback(
|
|
|
|
GetDisplay(), isMultiview ? OBSRenderMultiview : OBSRender,
|
|
|
|
this);
|
2018-02-19 19:54:37 +00:00
|
|
|
|
2016-02-23 23:16:51 +00:00
|
|
|
if (source)
|
|
|
|
obs_source_dec_showing(source);
|
2018-02-19 19:54:37 +00:00
|
|
|
|
|
|
|
if (isMultiview) {
|
|
|
|
for (OBSWeakSource &weakSrc : multiviewScenes) {
|
|
|
|
OBSSource src = OBSGetStrongRef(weakSrc);
|
|
|
|
if (src)
|
|
|
|
obs_source_dec_showing(src);
|
|
|
|
}
|
|
|
|
|
|
|
|
obs_enter_graphics();
|
2018-12-16 16:14:58 +00:00
|
|
|
gs_vertexbuffer_destroy(actionSafeMargin);
|
|
|
|
gs_vertexbuffer_destroy(graphicsSafeMargin);
|
|
|
|
gs_vertexbuffer_destroy(fourByThreeSafeMargin);
|
2018-02-19 19:54:37 +00:00
|
|
|
gs_vertexbuffer_destroy(leftLine);
|
|
|
|
gs_vertexbuffer_destroy(topLine);
|
|
|
|
gs_vertexbuffer_destroy(rightLine);
|
|
|
|
obs_leave_graphics();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == ProjectorType::Multiview)
|
|
|
|
multiviewProjectors.removeAll(this);
|
|
|
|
|
2016-02-23 23:16:51 +00:00
|
|
|
App()->DecrementSleepInhibition();
|
2020-10-01 20:15:25 +00:00
|
|
|
|
|
|
|
screen = nullptr;
|
2016-02-23 23:16:51 +00:00
|
|
|
}
|
|
|
|
|
2020-03-25 08:07:22 +00:00
|
|
|
void OBSProjector::SetMonitor(int monitor)
|
|
|
|
{
|
|
|
|
savedMonitor = monitor;
|
2020-10-01 20:15:25 +00:00
|
|
|
screen = QGuiApplication::screens()[monitor];
|
2020-03-25 08:07:22 +00:00
|
|
|
setGeometry(screen->geometry());
|
2020-05-27 20:57:19 +00:00
|
|
|
showFullScreen();
|
|
|
|
SetHideCursor();
|
2020-03-25 08:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OBSProjector::SetHideCursor()
|
|
|
|
{
|
2020-10-01 20:15:25 +00:00
|
|
|
if (savedMonitor == -1)
|
|
|
|
return;
|
|
|
|
|
2020-03-25 08:07:22 +00:00
|
|
|
bool hideCursor = config_get_bool(GetGlobalConfig(), "BasicWindow",
|
|
|
|
"HideProjectorCursor");
|
|
|
|
|
|
|
|
if (hideCursor && type != ProjectorType::Multiview)
|
|
|
|
setCursor(Qt::BlankCursor);
|
|
|
|
else
|
|
|
|
setCursor(Qt::ArrowCursor);
|
|
|
|
}
|
|
|
|
|
2018-02-19 19:54:37 +00:00
|
|
|
static OBSSource CreateLabel(const char *name, size_t h)
|
|
|
|
{
|
|
|
|
obs_data_t *settings = obs_data_create();
|
2019-09-22 21:19:10 +00:00
|
|
|
obs_data_t *font = obs_data_create();
|
2018-02-19 19:54:37 +00:00
|
|
|
|
|
|
|
std::string text;
|
|
|
|
text += " ";
|
|
|
|
text += name;
|
|
|
|
text += " ";
|
|
|
|
|
|
|
|
#if defined(_WIN32)
|
|
|
|
obs_data_set_string(font, "face", "Arial");
|
|
|
|
#elif defined(__APPLE__)
|
|
|
|
obs_data_set_string(font, "face", "Helvetica");
|
|
|
|
#else
|
|
|
|
obs_data_set_string(font, "face", "Monospace");
|
|
|
|
#endif
|
|
|
|
obs_data_set_int(font, "flags", 1); // Bold text
|
|
|
|
obs_data_set_int(font, "size", int(h / 9.81));
|
|
|
|
|
|
|
|
obs_data_set_obj(settings, "font", font);
|
|
|
|
obs_data_set_string(settings, "text", text.c_str());
|
|
|
|
obs_data_set_bool(settings, "outline", false);
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
const char *text_source_id = "text_gdiplus";
|
|
|
|
#else
|
|
|
|
const char *text_source_id = "text_ft2_source";
|
|
|
|
#endif
|
|
|
|
|
2019-09-22 21:19:10 +00:00
|
|
|
OBSSource txtSource =
|
|
|
|
obs_source_create_private(text_source_id, name, settings);
|
2018-02-19 19:54:37 +00:00
|
|
|
obs_source_release(txtSource);
|
|
|
|
|
|
|
|
obs_data_release(font);
|
|
|
|
obs_data_release(settings);
|
|
|
|
|
|
|
|
return txtSource;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint32_t labelOffset(obs_source_t *label, uint32_t cx)
|
|
|
|
{
|
|
|
|
uint32_t w = obs_source_get_width(label);
|
2018-12-16 16:14:58 +00:00
|
|
|
|
|
|
|
int n; // Number of scenes per row
|
|
|
|
switch (multiviewLayout) {
|
|
|
|
case MultiviewLayout::HORIZONTAL_TOP_24_SCENES:
|
|
|
|
n = 6;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
n = 4;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
w = uint32_t(w * ((1.0f) / n));
|
2018-02-19 19:54:37 +00:00
|
|
|
return (cx / 2) - w;
|
|
|
|
}
|
|
|
|
|
2018-12-16 16:14:58 +00:00
|
|
|
static inline void startRegion(int vX, int vY, int vCX, int vCY, float oL,
|
2019-09-22 21:19:10 +00:00
|
|
|
float oR, float oT, float oB)
|
2018-12-16 16:14:58 +00:00
|
|
|
{
|
|
|
|
gs_projection_push();
|
|
|
|
gs_viewport_push();
|
|
|
|
gs_set_viewport(vX, vY, vCX, vCY);
|
|
|
|
gs_ortho(oL, oR, oT, oB, -100.0f, 100.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void endRegion()
|
|
|
|
{
|
|
|
|
gs_viewport_pop();
|
|
|
|
gs_projection_pop();
|
|
|
|
}
|
|
|
|
|
2018-02-19 19:54:37 +00:00
|
|
|
void OBSProjector::OBSRenderMultiview(void *data, uint32_t cx, uint32_t cy)
|
|
|
|
{
|
|
|
|
OBSProjector *window = (OBSProjector *)data;
|
|
|
|
|
|
|
|
if (updatingMultiview || !window->ready)
|
|
|
|
return;
|
|
|
|
|
2019-09-22 21:19:10 +00:00
|
|
|
OBSBasic *main = (OBSBasic *)obs_frontend_get_main_window();
|
|
|
|
uint32_t targetCX, targetCY;
|
|
|
|
int x, y;
|
|
|
|
float scale;
|
2018-02-19 19:54:37 +00:00
|
|
|
|
2018-12-16 16:14:58 +00:00
|
|
|
targetCX = (uint32_t)window->fw;
|
|
|
|
targetCY = (uint32_t)window->fh;
|
2018-02-19 19:54:37 +00:00
|
|
|
|
|
|
|
GetScaleAndCenterPos(targetCX, targetCY, cx, cy, x, y, scale);
|
|
|
|
|
|
|
|
OBSSource previewSrc = main->GetCurrentSceneSource();
|
|
|
|
OBSSource programSrc = main->GetProgramSource();
|
|
|
|
bool studioMode = main->IsPreviewProgramMode();
|
|
|
|
|
2018-12-16 16:14:58 +00:00
|
|
|
auto renderVB = [&](gs_vertbuffer_t *vb, int cx, int cy,
|
2019-09-22 21:19:10 +00:00
|
|
|
uint32_t colorVal) {
|
2018-12-16 16:14:58 +00:00
|
|
|
if (!vb)
|
|
|
|
return;
|
|
|
|
|
|
|
|
matrix4 transform;
|
|
|
|
matrix4_identity(&transform);
|
|
|
|
transform.x.x = cx;
|
|
|
|
transform.y.y = cy;
|
|
|
|
|
|
|
|
gs_load_vertexbuffer(vb);
|
|
|
|
|
|
|
|
gs_matrix_push();
|
|
|
|
gs_matrix_mul(&transform);
|
|
|
|
|
|
|
|
gs_effect_set_color(window->color, colorVal);
|
|
|
|
while (gs_effect_loop(window->solid, "Solid"))
|
|
|
|
gs_draw(GS_LINESTRIP, 0, 0);
|
|
|
|
|
|
|
|
gs_matrix_pop();
|
|
|
|
};
|
|
|
|
|
2019-09-22 21:19:10 +00:00
|
|
|
auto drawBox = [&](float cx, float cy, uint32_t colorVal) {
|
2018-12-16 16:14:58 +00:00
|
|
|
gs_effect_set_color(window->color, colorVal);
|
|
|
|
while (gs_effect_loop(window->solid, "Solid"))
|
2018-02-19 19:54:37 +00:00
|
|
|
gs_draw_sprite(nullptr, 0, (uint32_t)cx, (uint32_t)cy);
|
|
|
|
};
|
|
|
|
|
2019-09-22 21:19:10 +00:00
|
|
|
auto setRegion = [&](float bx, float by, float cx, float cy) {
|
|
|
|
float vX = int(x + bx * scale);
|
|
|
|
float vY = int(y + by * scale);
|
2018-02-19 19:54:37 +00:00
|
|
|
float vCX = int(cx * scale);
|
|
|
|
float vCY = int(cy * scale);
|
|
|
|
|
2018-12-16 16:14:58 +00:00
|
|
|
float oL = bx;
|
|
|
|
float oT = by;
|
|
|
|
float oR = (bx + cx);
|
|
|
|
float oB = (by + cy);
|
2018-02-19 19:54:37 +00:00
|
|
|
|
2018-12-16 16:14:58 +00:00
|
|
|
startRegion(vX, vY, vCX, vCY, oL, oR, oT, oB);
|
2018-02-19 19:54:37 +00:00
|
|
|
};
|
|
|
|
|
2019-09-22 21:19:10 +00:00
|
|
|
auto calcBaseSource = [&](size_t i) {
|
2018-02-19 19:54:37 +00:00
|
|
|
switch (multiviewLayout) {
|
2018-12-16 16:14:58 +00:00
|
|
|
case MultiviewLayout::HORIZONTAL_TOP_24_SCENES:
|
|
|
|
window->sourceX = (i % 6) * window->scenesCX;
|
2019-09-22 21:19:10 +00:00
|
|
|
window->sourceY =
|
|
|
|
window->pvwprgCY + (i / 6) * window->scenesCY;
|
2018-12-16 16:14:58 +00:00
|
|
|
break;
|
|
|
|
case MultiviewLayout::VERTICAL_LEFT_8_SCENES:
|
|
|
|
window->sourceX = window->pvwprgCX;
|
2019-09-22 21:19:10 +00:00
|
|
|
window->sourceY = (i / 2) * window->scenesCY;
|
2018-02-19 19:54:37 +00:00
|
|
|
if (i % 2 != 0)
|
2018-12-16 16:14:58 +00:00
|
|
|
window->sourceX += window->scenesCX;
|
2018-02-19 19:54:37 +00:00
|
|
|
break;
|
2018-12-16 16:14:58 +00:00
|
|
|
case MultiviewLayout::VERTICAL_RIGHT_8_SCENES:
|
|
|
|
window->sourceX = 0;
|
2019-09-22 21:19:10 +00:00
|
|
|
window->sourceY = (i / 2) * window->scenesCY;
|
2018-02-19 19:54:37 +00:00
|
|
|
if (i % 2 != 0)
|
2018-12-16 16:14:58 +00:00
|
|
|
window->sourceX = window->scenesCX;
|
2018-02-19 19:54:37 +00:00
|
|
|
break;
|
2018-12-16 16:14:58 +00:00
|
|
|
case MultiviewLayout::HORIZONTAL_BOTTOM_8_SCENES:
|
2018-02-19 19:54:37 +00:00
|
|
|
if (i < 4) {
|
2018-12-16 16:14:58 +00:00
|
|
|
window->sourceX = (float(i) * window->scenesCX);
|
|
|
|
window->sourceY = 0;
|
2018-02-19 19:54:37 +00:00
|
|
|
} else {
|
2019-09-22 21:19:10 +00:00
|
|
|
window->sourceX =
|
|
|
|
(float(i - 4) * window->scenesCX);
|
2018-12-16 16:14:58 +00:00
|
|
|
window->sourceY = window->scenesCY;
|
2018-02-19 19:54:37 +00:00
|
|
|
}
|
|
|
|
break;
|
2018-12-16 16:14:58 +00:00
|
|
|
default: // MultiviewLayout::HORIZONTAL_TOP_8_SCENES:
|
2018-02-19 19:54:37 +00:00
|
|
|
if (i < 4) {
|
2018-12-16 16:14:58 +00:00
|
|
|
window->sourceX = (float(i) * window->scenesCX);
|
|
|
|
window->sourceY = window->pvwprgCY;
|
2018-02-19 19:54:37 +00:00
|
|
|
} else {
|
2019-09-22 21:19:10 +00:00
|
|
|
window->sourceX =
|
|
|
|
(float(i - 4) * window->scenesCX);
|
|
|
|
window->sourceY =
|
|
|
|
window->pvwprgCY + window->scenesCY;
|
2018-02-19 19:54:37 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-16 16:14:58 +00:00
|
|
|
window->siX = window->sourceX + window->thickness;
|
|
|
|
window->siY = window->sourceY + window->thickness;
|
2018-02-19 19:54:37 +00:00
|
|
|
};
|
|
|
|
|
2019-09-22 21:19:10 +00:00
|
|
|
auto calcPreviewProgram = [&](bool program) {
|
2018-02-19 19:54:37 +00:00
|
|
|
switch (multiviewLayout) {
|
2018-12-16 16:14:58 +00:00
|
|
|
case MultiviewLayout::HORIZONTAL_TOP_24_SCENES:
|
2019-09-22 21:19:10 +00:00
|
|
|
window->sourceX =
|
|
|
|
window->thickness + window->pvwprgCX / 2;
|
2018-12-16 16:14:58 +00:00
|
|
|
window->sourceY = window->thickness;
|
|
|
|
window->labelX = window->offset + window->pvwprgCX / 2;
|
|
|
|
window->labelY = window->pvwprgCY * 0.85f;
|
|
|
|
if (program) {
|
|
|
|
window->sourceX += window->pvwprgCX;
|
|
|
|
window->labelX += window->pvwprgCX;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MultiviewLayout::VERTICAL_LEFT_8_SCENES:
|
|
|
|
window->sourceX = window->thickness;
|
|
|
|
window->sourceY = window->pvwprgCY + window->thickness;
|
|
|
|
window->labelX = window->offset;
|
|
|
|
window->labelY = window->pvwprgCY * 1.85f;
|
2018-02-19 19:54:37 +00:00
|
|
|
if (program) {
|
2018-12-16 16:14:58 +00:00
|
|
|
window->sourceY = window->thickness;
|
|
|
|
window->labelY = window->pvwprgCY * 0.85f;
|
2018-02-19 19:54:37 +00:00
|
|
|
}
|
|
|
|
break;
|
2018-12-16 16:14:58 +00:00
|
|
|
case MultiviewLayout::VERTICAL_RIGHT_8_SCENES:
|
|
|
|
window->sourceX = window->pvwprgCX + window->thickness;
|
|
|
|
window->sourceY = window->pvwprgCY + window->thickness;
|
|
|
|
window->labelX = window->pvwprgCX + window->offset;
|
|
|
|
window->labelY = window->pvwprgCY * 1.85f;
|
2018-02-19 19:54:37 +00:00
|
|
|
if (program) {
|
2018-12-16 16:14:58 +00:00
|
|
|
window->sourceY = window->thickness;
|
|
|
|
window->labelY = window->pvwprgCY * 0.85f;
|
2018-02-19 19:54:37 +00:00
|
|
|
}
|
|
|
|
break;
|
2018-12-16 16:14:58 +00:00
|
|
|
case MultiviewLayout::HORIZONTAL_BOTTOM_8_SCENES:
|
|
|
|
window->sourceX = window->thickness;
|
|
|
|
window->sourceY = window->pvwprgCY + window->thickness;
|
|
|
|
window->labelX = window->offset;
|
|
|
|
window->labelY = window->pvwprgCY * 1.85f;
|
2018-02-19 19:54:37 +00:00
|
|
|
if (program) {
|
2018-12-16 16:14:58 +00:00
|
|
|
window->sourceX += window->pvwprgCX;
|
|
|
|
window->labelX += window->pvwprgCX;
|
2018-02-19 19:54:37 +00:00
|
|
|
}
|
|
|
|
break;
|
2018-12-16 16:14:58 +00:00
|
|
|
default: // MultiviewLayout::HORIZONTAL_TOP_8_SCENES:
|
|
|
|
window->sourceX = window->thickness;
|
|
|
|
window->sourceY = window->thickness;
|
|
|
|
window->labelX = window->offset;
|
|
|
|
window->labelY = window->pvwprgCY * 0.85f;
|
2018-02-19 19:54:37 +00:00
|
|
|
if (program) {
|
2018-12-16 16:14:58 +00:00
|
|
|
window->sourceX += window->pvwprgCX;
|
|
|
|
window->labelX += window->pvwprgCX;
|
2018-02-19 19:54:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-12-16 16:14:58 +00:00
|
|
|
auto paintAreaWithColor = [&](float tx, float ty, float cx, float cy,
|
2019-09-22 21:19:10 +00:00
|
|
|
uint32_t color) {
|
2018-12-16 16:14:58 +00:00
|
|
|
gs_matrix_push();
|
|
|
|
gs_matrix_translate3f(tx, ty, 0.0f);
|
|
|
|
drawBox(cx, cy, color);
|
|
|
|
gs_matrix_pop();
|
|
|
|
};
|
2018-02-19 19:54:37 +00:00
|
|
|
|
2018-12-16 16:14:58 +00:00
|
|
|
// Define the whole usable region for the multiview
|
|
|
|
startRegion(x, y, targetCX * scale, targetCY * scale, 0.0f, window->fw,
|
2019-09-22 21:19:10 +00:00
|
|
|
0.0f, window->fh);
|
2018-02-19 19:54:37 +00:00
|
|
|
|
2018-12-16 16:14:58 +00:00
|
|
|
// Change the background color to highlight all sources
|
|
|
|
drawBox(window->fw, window->fh, outerColor);
|
2018-02-19 19:54:37 +00:00
|
|
|
|
2018-12-16 16:14:58 +00:00
|
|
|
/* ----------------------------- */
|
|
|
|
/* draw sources */
|
2018-02-19 19:54:37 +00:00
|
|
|
|
2018-12-16 16:14:58 +00:00
|
|
|
for (size_t i = 0; i < maxSrcs; i++) {
|
|
|
|
// Handle all the offsets
|
2018-02-19 19:54:37 +00:00
|
|
|
calcBaseSource(i);
|
|
|
|
|
2018-12-16 16:14:58 +00:00
|
|
|
if (i >= numSrcs) {
|
|
|
|
// Just paint the background and continue
|
|
|
|
paintAreaWithColor(window->sourceX, window->sourceY,
|
2019-09-22 21:19:10 +00:00
|
|
|
window->scenesCX, window->scenesCY,
|
|
|
|
outerColor);
|
2018-12-16 16:14:58 +00:00
|
|
|
paintAreaWithColor(window->siX, window->siY,
|
2019-09-22 21:19:10 +00:00
|
|
|
window->siCX, window->siCY,
|
|
|
|
backgroundColor);
|
2018-12-16 16:14:58 +00:00
|
|
|
continue;
|
|
|
|
}
|
2018-02-19 19:54:37 +00:00
|
|
|
|
2018-12-16 16:14:58 +00:00
|
|
|
OBSSource src = OBSGetStrongRef(window->multiviewScenes[i]);
|
2018-02-19 19:54:37 +00:00
|
|
|
|
2018-12-16 16:14:58 +00:00
|
|
|
// We have a source. Now chose the proper highlight color
|
|
|
|
uint32_t colorVal = outerColor;
|
|
|
|
if (src == programSrc)
|
|
|
|
colorVal = programColor;
|
|
|
|
else if (src == previewSrc)
|
|
|
|
colorVal = studioMode ? previewColor : programColor;
|
2018-02-19 19:54:37 +00:00
|
|
|
|
2018-12-16 16:14:58 +00:00
|
|
|
// Paint the background
|
|
|
|
paintAreaWithColor(window->sourceX, window->sourceY,
|
2019-09-22 21:19:10 +00:00
|
|
|
window->scenesCX, window->scenesCY,
|
|
|
|
colorVal);
|
2018-12-16 16:14:58 +00:00
|
|
|
paintAreaWithColor(window->siX, window->siY, window->siCX,
|
2019-09-22 21:19:10 +00:00
|
|
|
window->siCY, backgroundColor);
|
2018-02-19 19:54:37 +00:00
|
|
|
|
|
|
|
/* ----------- */
|
|
|
|
|
2018-12-16 16:14:58 +00:00
|
|
|
// Render the source
|
2018-02-19 19:54:37 +00:00
|
|
|
gs_matrix_push();
|
2018-12-16 16:14:58 +00:00
|
|
|
gs_matrix_translate3f(window->siX, window->siY, 0.0f);
|
|
|
|
gs_matrix_scale3f(window->siScaleX, window->siScaleY, 1.0f);
|
|
|
|
setRegion(window->siX, window->siY, window->siCX, window->siCY);
|
2018-02-19 19:54:37 +00:00
|
|
|
obs_source_video_render(src);
|
2018-12-16 16:14:58 +00:00
|
|
|
endRegion();
|
2018-02-19 19:54:37 +00:00
|
|
|
gs_matrix_pop();
|
|
|
|
|
|
|
|
/* ----------- */
|
|
|
|
|
2018-12-16 16:14:58 +00:00
|
|
|
// Render the label
|
|
|
|
if (!drawLabel)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
obs_source *label = window->multiviewLabels[i + 2];
|
|
|
|
if (!label)
|
|
|
|
continue;
|
2018-02-19 19:54:37 +00:00
|
|
|
|
2018-12-16 16:14:58 +00:00
|
|
|
window->offset = labelOffset(label, window->scenesCX);
|
2018-02-19 19:54:37 +00:00
|
|
|
|
2018-12-16 16:14:58 +00:00
|
|
|
gs_matrix_push();
|
2019-09-22 21:19:10 +00:00
|
|
|
gs_matrix_translate3f(
|
|
|
|
window->sourceX + window->offset,
|
|
|
|
(window->scenesCY * 0.85f) + window->sourceY, 0.0f);
|
2018-12-16 16:14:58 +00:00
|
|
|
gs_matrix_scale3f(window->ppiScaleX, window->ppiScaleY, 1.0f);
|
|
|
|
drawBox(obs_source_get_width(label),
|
2019-09-22 21:19:10 +00:00
|
|
|
obs_source_get_height(label) +
|
|
|
|
int(window->sourceY * 0.015f),
|
|
|
|
labelColor);
|
2018-02-19 19:54:37 +00:00
|
|
|
obs_source_video_render(label);
|
|
|
|
gs_matrix_pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------------------- */
|
|
|
|
/* draw preview */
|
|
|
|
|
|
|
|
obs_source_t *previewLabel = window->multiviewLabels[0];
|
2018-12-16 16:14:58 +00:00
|
|
|
window->offset = labelOffset(previewLabel, window->pvwprgCX);
|
2018-02-19 19:54:37 +00:00
|
|
|
calcPreviewProgram(false);
|
|
|
|
|
2018-12-16 16:14:58 +00:00
|
|
|
// Paint the background
|
|
|
|
paintAreaWithColor(window->sourceX, window->sourceY, window->ppiCX,
|
2019-09-22 21:19:10 +00:00
|
|
|
window->ppiCY, backgroundColor);
|
2018-02-19 19:54:37 +00:00
|
|
|
|
2018-12-16 16:14:58 +00:00
|
|
|
// Scale and Draw the preview
|
|
|
|
gs_matrix_push();
|
|
|
|
gs_matrix_translate3f(window->sourceX, window->sourceY, 0.0f);
|
|
|
|
gs_matrix_scale3f(window->ppiScaleX, window->ppiScaleY, 1.0f);
|
|
|
|
setRegion(window->sourceX, window->sourceY, window->ppiCX,
|
2019-09-22 21:19:10 +00:00
|
|
|
window->ppiCY);
|
2018-12-16 16:14:58 +00:00
|
|
|
if (studioMode)
|
2018-02-19 19:54:37 +00:00
|
|
|
obs_source_video_render(previewSrc);
|
2018-12-16 16:14:58 +00:00
|
|
|
else
|
2018-02-19 19:54:37 +00:00
|
|
|
obs_render_main_texture();
|
2018-12-16 16:14:58 +00:00
|
|
|
if (drawSafeArea) {
|
|
|
|
renderVB(window->actionSafeMargin, targetCX, targetCY,
|
2019-09-22 21:19:10 +00:00
|
|
|
outerColor);
|
2018-12-16 16:14:58 +00:00
|
|
|
renderVB(window->graphicsSafeMargin, targetCX, targetCY,
|
2019-09-22 21:19:10 +00:00
|
|
|
outerColor);
|
2018-12-16 16:14:58 +00:00
|
|
|
renderVB(window->fourByThreeSafeMargin, targetCX, targetCY,
|
2019-09-22 21:19:10 +00:00
|
|
|
outerColor);
|
2018-12-16 16:14:58 +00:00
|
|
|
renderVB(window->leftLine, targetCX, targetCY, outerColor);
|
|
|
|
renderVB(window->topLine, targetCX, targetCY, outerColor);
|
|
|
|
renderVB(window->rightLine, targetCX, targetCY, outerColor);
|
2018-02-19 19:54:37 +00:00
|
|
|
}
|
2018-12-16 16:14:58 +00:00
|
|
|
endRegion();
|
2018-02-19 19:54:37 +00:00
|
|
|
gs_matrix_pop();
|
|
|
|
|
|
|
|
/* ----------- */
|
|
|
|
|
2018-12-16 16:14:58 +00:00
|
|
|
// Draw the Label
|
|
|
|
if (drawLabel) {
|
|
|
|
gs_matrix_push();
|
|
|
|
gs_matrix_translate3f(window->labelX, window->labelY, 0.0f);
|
|
|
|
gs_matrix_scale3f(window->ppiScaleX, window->ppiScaleY, 1.0f);
|
|
|
|
drawBox(obs_source_get_width(previewLabel),
|
2019-09-22 21:19:10 +00:00
|
|
|
obs_source_get_height(previewLabel) +
|
|
|
|
int(window->pvwprgCX * 0.015f),
|
|
|
|
labelColor);
|
2018-12-16 16:14:58 +00:00
|
|
|
obs_source_video_render(previewLabel);
|
|
|
|
gs_matrix_pop();
|
|
|
|
}
|
2018-02-19 19:54:37 +00:00
|
|
|
|
|
|
|
/* ----------------------------- */
|
|
|
|
/* draw program */
|
|
|
|
|
|
|
|
obs_source_t *programLabel = window->multiviewLabels[1];
|
2018-12-16 16:14:58 +00:00
|
|
|
window->offset = labelOffset(programLabel, window->pvwprgCX);
|
2018-02-19 19:54:37 +00:00
|
|
|
calcPreviewProgram(true);
|
|
|
|
|
2019-07-27 12:47:10 +00:00
|
|
|
paintAreaWithColor(window->sourceX, window->sourceY, window->ppiCX,
|
2019-09-22 21:19:10 +00:00
|
|
|
window->ppiCY, backgroundColor);
|
2019-07-27 12:47:10 +00:00
|
|
|
|
2018-12-16 16:14:58 +00:00
|
|
|
// Scale and Draw the program
|
2018-02-19 19:54:37 +00:00
|
|
|
gs_matrix_push();
|
2018-12-16 16:14:58 +00:00
|
|
|
gs_matrix_translate3f(window->sourceX, window->sourceY, 0.0f);
|
|
|
|
gs_matrix_scale3f(window->ppiScaleX, window->ppiScaleY, 1.0f);
|
|
|
|
setRegion(window->sourceX, window->sourceY, window->ppiCX,
|
2019-09-22 21:19:10 +00:00
|
|
|
window->ppiCY);
|
2018-02-19 19:54:37 +00:00
|
|
|
obs_render_main_texture();
|
2018-12-16 16:14:58 +00:00
|
|
|
endRegion();
|
2018-02-19 19:54:37 +00:00
|
|
|
gs_matrix_pop();
|
|
|
|
|
|
|
|
/* ----------- */
|
|
|
|
|
2018-12-16 16:14:58 +00:00
|
|
|
// Draw the Label
|
|
|
|
if (drawLabel) {
|
|
|
|
gs_matrix_push();
|
|
|
|
gs_matrix_translate3f(window->labelX, window->labelY, 0.0f);
|
|
|
|
gs_matrix_scale3f(window->ppiScaleX, window->ppiScaleY, 1.0f);
|
|
|
|
drawBox(obs_source_get_width(programLabel),
|
2019-09-22 21:19:10 +00:00
|
|
|
obs_source_get_height(programLabel) +
|
|
|
|
int(window->pvwprgCX * 0.015f),
|
|
|
|
labelColor);
|
2018-12-16 16:14:58 +00:00
|
|
|
obs_source_video_render(programLabel);
|
|
|
|
gs_matrix_pop();
|
|
|
|
}
|
2018-02-19 19:54:37 +00:00
|
|
|
|
2020-03-25 08:07:22 +00:00
|
|
|
// Region for future usage with additional info.
|
2018-12-16 16:14:58 +00:00
|
|
|
if (multiviewLayout == MultiviewLayout::HORIZONTAL_TOP_24_SCENES) {
|
|
|
|
// Just paint the background for now
|
|
|
|
paintAreaWithColor(window->thickness, window->thickness,
|
2019-09-22 21:19:10 +00:00
|
|
|
window->siCX,
|
|
|
|
window->siCY * 2 + window->thicknessx2,
|
|
|
|
backgroundColor);
|
|
|
|
paintAreaWithColor(
|
|
|
|
window->thickness +
|
|
|
|
2.5 * (window->thicknessx2 + window->ppiCX),
|
|
|
|
window->thickness, window->siCX,
|
|
|
|
window->siCY * 2 + window->thicknessx2,
|
|
|
|
backgroundColor);
|
2018-12-16 16:14:58 +00:00
|
|
|
}
|
2018-02-19 19:54:37 +00:00
|
|
|
|
2018-12-16 16:14:58 +00:00
|
|
|
endRegion();
|
2016-02-23 23:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OBSProjector::OBSRender(void *data, uint32_t cx, uint32_t cy)
|
|
|
|
{
|
2019-09-22 21:19:10 +00:00
|
|
|
OBSProjector *window = reinterpret_cast<OBSProjector *>(data);
|
2016-02-23 23:16:51 +00:00
|
|
|
|
2018-02-19 19:54:37 +00:00
|
|
|
if (!window->ready)
|
|
|
|
return;
|
|
|
|
|
2019-09-22 21:19:10 +00:00
|
|
|
OBSBasic *main = reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
|
2018-12-16 16:14:58 +00:00
|
|
|
OBSSource source = window->source;
|
2018-02-19 19:54:37 +00:00
|
|
|
|
2016-02-23 23:16:51 +00:00
|
|
|
uint32_t targetCX;
|
|
|
|
uint32_t targetCY;
|
2019-09-22 21:19:10 +00:00
|
|
|
int x, y;
|
|
|
|
int newCX, newCY;
|
|
|
|
float scale;
|
2016-02-23 23:16:51 +00:00
|
|
|
|
2018-12-16 16:14:58 +00:00
|
|
|
if (source) {
|
|
|
|
targetCX = std::max(obs_source_get_width(source), 1u);
|
|
|
|
targetCY = std::max(obs_source_get_height(source), 1u);
|
2016-02-23 23:16:51 +00:00
|
|
|
} else {
|
|
|
|
struct obs_video_info ovi;
|
|
|
|
obs_get_video_info(&ovi);
|
|
|
|
targetCX = ovi.base_width;
|
|
|
|
targetCY = ovi.base_height;
|
|
|
|
}
|
|
|
|
|
|
|
|
GetScaleAndCenterPos(targetCX, targetCY, cx, cy, x, y, scale);
|
|
|
|
|
|
|
|
newCX = int(scale * float(targetCX));
|
|
|
|
newCY = int(scale * float(targetCY));
|
|
|
|
|
2018-12-16 16:14:58 +00:00
|
|
|
startRegion(x, y, newCX, newCY, 0.0f, float(targetCX), 0.0f,
|
2019-09-22 21:19:10 +00:00
|
|
|
float(targetCY));
|
2018-02-19 19:54:37 +00:00
|
|
|
|
|
|
|
if (window->type == ProjectorType::Preview &&
|
|
|
|
main->IsPreviewProgramMode()) {
|
|
|
|
OBSSource curSource = main->GetCurrentSceneSource();
|
|
|
|
|
2018-12-16 16:14:58 +00:00
|
|
|
if (source != curSource) {
|
|
|
|
obs_source_dec_showing(source);
|
2018-02-19 19:54:37 +00:00
|
|
|
obs_source_inc_showing(curSource);
|
|
|
|
source = curSource;
|
2019-07-27 12:47:10 +00:00
|
|
|
window->source = source;
|
2018-02-19 19:54:37 +00:00
|
|
|
}
|
2019-12-10 19:31:54 +00:00
|
|
|
} else if (window->type == ProjectorType::Preview &&
|
|
|
|
!main->IsPreviewProgramMode()) {
|
|
|
|
window->source = nullptr;
|
2018-02-19 19:54:37 +00:00
|
|
|
}
|
|
|
|
|
2018-12-16 16:14:58 +00:00
|
|
|
if (source)
|
2018-02-19 19:54:37 +00:00
|
|
|
obs_source_video_render(source);
|
2018-12-16 16:14:58 +00:00
|
|
|
else
|
2018-02-19 19:54:37 +00:00
|
|
|
obs_render_main_texture();
|
2016-02-23 23:16:51 +00:00
|
|
|
|
2018-12-16 16:14:58 +00:00
|
|
|
endRegion();
|
2016-02-23 23:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OBSProjector::OBSSourceRemoved(void *data, calldata_t *params)
|
|
|
|
{
|
2019-09-22 21:19:10 +00:00
|
|
|
OBSProjector *window = reinterpret_cast<OBSProjector *>(data);
|
2017-04-19 19:54:15 +00:00
|
|
|
|
2016-02-23 23:16:51 +00:00
|
|
|
window->deleteLater();
|
|
|
|
|
|
|
|
UNUSED_PARAMETER(params);
|
|
|
|
}
|
|
|
|
|
2018-12-16 16:14:58 +00:00
|
|
|
static int getSourceByPosition(int x, int y, float ratio)
|
2018-02-19 19:54:37 +00:00
|
|
|
{
|
2018-12-16 16:14:58 +00:00
|
|
|
int pos = -1;
|
|
|
|
QWidget *rec = QApplication::activeWindow();
|
|
|
|
if (!rec)
|
|
|
|
return pos;
|
2019-09-22 21:19:10 +00:00
|
|
|
int cx = rec->width();
|
|
|
|
int cy = rec->height();
|
|
|
|
int minX = 0;
|
|
|
|
int minY = 0;
|
|
|
|
int maxX = cx;
|
|
|
|
int maxY = cy;
|
2018-02-19 19:54:37 +00:00
|
|
|
|
|
|
|
switch (multiviewLayout) {
|
2018-12-16 16:14:58 +00:00
|
|
|
case MultiviewLayout::HORIZONTAL_TOP_24_SCENES:
|
|
|
|
if (float(cx) / float(cy) > ratio) {
|
|
|
|
int validX = cy * ratio;
|
|
|
|
minX = (cx / 2) - (validX / 2);
|
|
|
|
maxX = (cx / 2) + (validX / 2);
|
|
|
|
minY = cy / 3;
|
|
|
|
} else {
|
|
|
|
int validY = cx / ratio;
|
|
|
|
maxY = (cy / 2) + (validY / 2);
|
|
|
|
minY = (cy / 2) - (validY / 6);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (x < minX || x > maxX || y < minY || y > maxY)
|
|
|
|
break;
|
|
|
|
|
|
|
|
pos = (x - minX) / ((maxX - minX) / 6);
|
|
|
|
pos += ((y - minY) / ((maxY - minY) / 4)) * 6;
|
|
|
|
|
|
|
|
break;
|
|
|
|
case MultiviewLayout::VERTICAL_LEFT_8_SCENES:
|
2018-02-19 19:54:37 +00:00
|
|
|
if (float(cx) / float(cy) > ratio) {
|
|
|
|
int validX = cy * ratio;
|
2018-12-16 16:14:58 +00:00
|
|
|
maxX = (cx / 2) + (validX / 2);
|
2018-02-19 19:54:37 +00:00
|
|
|
} else {
|
|
|
|
int validY = cx / ratio;
|
2018-12-16 16:14:58 +00:00
|
|
|
minY = (cy / 2) - (validY / 2);
|
|
|
|
maxY = (cy / 2) + (validY / 2);
|
2018-02-19 19:54:37 +00:00
|
|
|
}
|
|
|
|
|
2018-12-16 16:14:58 +00:00
|
|
|
minX = cx / 2;
|
2018-02-19 19:54:37 +00:00
|
|
|
|
|
|
|
if (x < minX || x > maxX || y < minY || y > maxY)
|
|
|
|
break;
|
|
|
|
|
|
|
|
pos = 2 * ((y - minY) / ((maxY - minY) / 4));
|
|
|
|
if (x > minX + ((maxX - minX) / 2))
|
|
|
|
pos++;
|
|
|
|
break;
|
2018-12-16 16:14:58 +00:00
|
|
|
case MultiviewLayout::VERTICAL_RIGHT_8_SCENES:
|
2018-02-19 19:54:37 +00:00
|
|
|
if (float(cx) / float(cy) > ratio) {
|
|
|
|
int validX = cy * ratio;
|
2018-12-16 16:14:58 +00:00
|
|
|
minX = (cx / 2) - (validX / 2);
|
2018-02-19 19:54:37 +00:00
|
|
|
} else {
|
|
|
|
int validY = cx / ratio;
|
2018-12-16 16:14:58 +00:00
|
|
|
minY = (cy / 2) - (validY / 2);
|
|
|
|
maxY = (cy / 2) + (validY / 2);
|
2018-02-19 19:54:37 +00:00
|
|
|
}
|
|
|
|
|
2018-12-16 16:14:58 +00:00
|
|
|
maxX = (cx / 2);
|
2018-02-19 19:54:37 +00:00
|
|
|
|
|
|
|
if (x < minX || x > maxX || y < minY || y > maxY)
|
|
|
|
break;
|
|
|
|
|
|
|
|
pos = 2 * ((y - minY) / ((maxY - minY) / 4));
|
|
|
|
if (x > minX + ((maxX - minX) / 2))
|
|
|
|
pos++;
|
|
|
|
break;
|
2018-12-16 16:14:58 +00:00
|
|
|
case MultiviewLayout::HORIZONTAL_BOTTOM_8_SCENES:
|
2018-02-19 19:54:37 +00:00
|
|
|
if (float(cx) / float(cy) > ratio) {
|
|
|
|
int validX = cy * ratio;
|
2018-12-16 16:14:58 +00:00
|
|
|
minX = (cx / 2) - (validX / 2);
|
|
|
|
maxX = (cx / 2) + (validX / 2);
|
2018-02-19 19:54:37 +00:00
|
|
|
} else {
|
|
|
|
int validY = cx / ratio;
|
2018-12-16 16:14:58 +00:00
|
|
|
minY = (cy / 2) - (validY / 2);
|
2018-02-19 19:54:37 +00:00
|
|
|
}
|
|
|
|
|
2018-12-16 16:14:58 +00:00
|
|
|
maxY = (cy / 2);
|
2018-02-19 19:54:37 +00:00
|
|
|
|
|
|
|
if (x < minX || x > maxX || y < minY || y > maxY)
|
|
|
|
break;
|
|
|
|
|
|
|
|
pos = (x - minX) / ((maxX - minX) / 4);
|
|
|
|
if (y > minY + ((maxY - minY) / 2))
|
|
|
|
pos += 4;
|
|
|
|
break;
|
2018-12-16 16:14:58 +00:00
|
|
|
default: // MultiviewLayout::HORIZONTAL_TOP_8_SCENES
|
2018-02-19 19:54:37 +00:00
|
|
|
if (float(cx) / float(cy) > ratio) {
|
|
|
|
int validX = cy * ratio;
|
2018-12-16 16:14:58 +00:00
|
|
|
minX = (cx / 2) - (validX / 2);
|
|
|
|
maxX = (cx / 2) + (validX / 2);
|
2018-02-19 19:54:37 +00:00
|
|
|
} else {
|
|
|
|
int validY = cx / ratio;
|
2018-12-16 16:14:58 +00:00
|
|
|
maxY = (cy / 2) + (validY / 2);
|
2018-02-19 19:54:37 +00:00
|
|
|
}
|
|
|
|
|
2018-12-16 16:14:58 +00:00
|
|
|
minY = (cy / 2);
|
2018-02-19 19:54:37 +00:00
|
|
|
|
|
|
|
if (x < minX || x > maxX || y < minY || y > maxY)
|
|
|
|
break;
|
|
|
|
|
|
|
|
pos = (x - minX) / ((maxX - minX) / 4);
|
|
|
|
if (y > minY + ((maxY - minY) / 2))
|
|
|
|
pos += 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OBSProjector::mouseDoubleClickEvent(QMouseEvent *event)
|
|
|
|
{
|
|
|
|
OBSQTDisplay::mouseDoubleClickEvent(event);
|
|
|
|
|
2018-12-16 16:14:58 +00:00
|
|
|
if (!mouseSwitching)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!transitionOnDoubleClick)
|
2018-02-19 19:54:37 +00:00
|
|
|
return;
|
|
|
|
|
2019-09-22 21:19:10 +00:00
|
|
|
OBSBasic *main = (OBSBasic *)obs_frontend_get_main_window();
|
2018-02-19 19:54:37 +00:00
|
|
|
if (!main->IsPreviewProgramMode())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (event->button() == Qt::LeftButton) {
|
2018-12-16 16:14:58 +00:00
|
|
|
int pos = getSourceByPosition(event->x(), event->y(), ratio);
|
|
|
|
if (pos < 0 || pos >= (int)numSrcs)
|
2018-02-19 19:54:37 +00:00
|
|
|
return;
|
|
|
|
OBSSource src = OBSGetStrongRef(multiviewScenes[pos]);
|
|
|
|
if (!src)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (main->GetProgramSource() != src)
|
|
|
|
main->TransitionToScene(src);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-23 23:16:51 +00:00
|
|
|
void OBSProjector::mousePressEvent(QMouseEvent *event)
|
|
|
|
{
|
|
|
|
OBSQTDisplay::mousePressEvent(event);
|
|
|
|
|
|
|
|
if (event->button() == Qt::RightButton) {
|
2020-03-25 08:07:22 +00:00
|
|
|
OBSBasic *main =
|
|
|
|
reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
|
2016-02-23 23:16:51 +00:00
|
|
|
QMenu popup(this);
|
2020-03-25 08:07:22 +00:00
|
|
|
|
|
|
|
QMenu *projectorMenu = new QMenu(QTStr("Fullscreen"));
|
|
|
|
main->AddProjectorMenuMonitors(projectorMenu, this,
|
|
|
|
SLOT(OpenFullScreenProjector()));
|
|
|
|
popup.addMenu(projectorMenu);
|
|
|
|
|
2020-10-01 20:15:25 +00:00
|
|
|
if (GetMonitor() > -1) {
|
2020-03-25 08:07:22 +00:00
|
|
|
popup.addAction(QTStr("Windowed"), this,
|
|
|
|
SLOT(OpenWindowedProjector()));
|
|
|
|
|
2020-10-01 20:15:25 +00:00
|
|
|
} else if (!this->isMaximized()) {
|
|
|
|
popup.addAction(QTStr("ResizeProjectorWindowToContent"),
|
|
|
|
this, SLOT(ResizeToContent()));
|
|
|
|
}
|
|
|
|
|
|
|
|
QAction *alwaysOnTopButton =
|
|
|
|
new QAction(QTStr("Basic.MainMenu.AlwaysOnTop"), this);
|
|
|
|
alwaysOnTopButton->setCheckable(true);
|
|
|
|
alwaysOnTopButton->setChecked(isAlwaysOnTop);
|
|
|
|
|
|
|
|
connect(alwaysOnTopButton, &QAction::toggled, this,
|
|
|
|
&OBSProjector::AlwaysOnTopToggled);
|
|
|
|
|
|
|
|
popup.addAction(alwaysOnTopButton);
|
|
|
|
|
2016-02-23 23:16:51 +00:00
|
|
|
popup.addAction(QTStr("Close"), this, SLOT(EscapeTriggered()));
|
|
|
|
popup.exec(QCursor::pos());
|
|
|
|
}
|
2018-02-19 19:54:37 +00:00
|
|
|
|
2018-12-16 16:14:58 +00:00
|
|
|
if (!mouseSwitching)
|
|
|
|
return;
|
|
|
|
|
2018-02-19 19:54:37 +00:00
|
|
|
if (event->button() == Qt::LeftButton) {
|
2018-12-16 16:14:58 +00:00
|
|
|
int pos = getSourceByPosition(event->x(), event->y(), ratio);
|
|
|
|
if (pos < 0 || pos >= (int)numSrcs)
|
2018-02-19 19:54:37 +00:00
|
|
|
return;
|
|
|
|
OBSSource src = OBSGetStrongRef(multiviewScenes[pos]);
|
|
|
|
if (!src)
|
|
|
|
return;
|
|
|
|
|
2019-09-22 21:19:10 +00:00
|
|
|
OBSBasic *main = (OBSBasic *)obs_frontend_get_main_window();
|
2018-02-19 19:54:37 +00:00
|
|
|
if (main->GetCurrentSceneSource() != src)
|
|
|
|
main->SetCurrentScene(src, false);
|
|
|
|
}
|
2016-02-23 23:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OBSProjector::EscapeTriggered()
|
|
|
|
{
|
2020-03-25 08:07:22 +00:00
|
|
|
OBSBasic *main = reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
|
|
|
|
main->DeleteProjector(this);
|
2020-10-01 20:15:25 +00:00
|
|
|
|
|
|
|
allProjectors.removeAll(this);
|
2016-02-23 23:16:51 +00:00
|
|
|
}
|
2018-02-19 19:54:37 +00:00
|
|
|
|
|
|
|
void OBSProjector::UpdateMultiview()
|
|
|
|
{
|
2018-12-16 16:14:58 +00:00
|
|
|
multiviewScenes.clear();
|
|
|
|
multiviewLabels.clear();
|
2018-02-19 19:54:37 +00:00
|
|
|
|
|
|
|
struct obs_video_info ovi;
|
|
|
|
obs_get_video_info(&ovi);
|
|
|
|
|
2019-09-22 21:19:10 +00:00
|
|
|
uint32_t w = ovi.base_width;
|
|
|
|
uint32_t h = ovi.base_height;
|
|
|
|
fw = float(w);
|
|
|
|
fh = float(h);
|
|
|
|
ratio = fw / fh;
|
2018-02-19 19:54:37 +00:00
|
|
|
|
|
|
|
struct obs_frontend_source_list scenes = {};
|
|
|
|
obs_frontend_get_scenes(&scenes);
|
|
|
|
|
2019-09-22 21:19:10 +00:00
|
|
|
multiviewLabels.emplace_back(
|
|
|
|
CreateLabel(Str("StudioMode.Preview"), h / 2));
|
|
|
|
multiviewLabels.emplace_back(
|
|
|
|
CreateLabel(Str("StudioMode.Program"), h / 2));
|
2018-12-16 16:14:58 +00:00
|
|
|
|
|
|
|
multiviewLayout = static_cast<MultiviewLayout>(config_get_int(
|
2019-09-22 21:19:10 +00:00
|
|
|
GetGlobalConfig(), "BasicWindow", "MultiviewLayout"));
|
2018-12-16 16:14:58 +00:00
|
|
|
|
2019-09-22 21:19:10 +00:00
|
|
|
drawLabel = config_get_bool(GetGlobalConfig(), "BasicWindow",
|
|
|
|
"MultiviewDrawNames");
|
2018-12-16 16:14:58 +00:00
|
|
|
|
|
|
|
drawSafeArea = config_get_bool(GetGlobalConfig(), "BasicWindow",
|
2019-09-22 21:19:10 +00:00
|
|
|
"MultiviewDrawAreas");
|
2018-12-16 16:14:58 +00:00
|
|
|
|
|
|
|
mouseSwitching = config_get_bool(GetGlobalConfig(), "BasicWindow",
|
2019-09-22 21:19:10 +00:00
|
|
|
"MultiviewMouseSwitch");
|
2018-02-19 19:54:37 +00:00
|
|
|
|
2019-09-22 21:19:10 +00:00
|
|
|
transitionOnDoubleClick = config_get_bool(
|
|
|
|
GetGlobalConfig(), "BasicWindow", "TransitionOnDoubleClick");
|
2018-02-19 19:54:37 +00:00
|
|
|
|
2019-09-22 21:19:10 +00:00
|
|
|
switch (multiviewLayout) {
|
2018-12-16 16:14:58 +00:00
|
|
|
case MultiviewLayout::HORIZONTAL_TOP_24_SCENES:
|
2019-09-22 21:19:10 +00:00
|
|
|
pvwprgCX = fw / 3;
|
|
|
|
pvwprgCY = fh / 3;
|
2018-12-16 16:14:58 +00:00
|
|
|
|
|
|
|
maxSrcs = 24;
|
|
|
|
break;
|
|
|
|
default:
|
2019-09-22 21:19:10 +00:00
|
|
|
pvwprgCX = fw / 2;
|
|
|
|
pvwprgCY = fh / 2;
|
2018-12-16 16:14:58 +00:00
|
|
|
|
|
|
|
maxSrcs = 8;
|
|
|
|
}
|
|
|
|
|
2019-09-22 21:19:10 +00:00
|
|
|
ppiCX = pvwprgCX - thicknessx2;
|
|
|
|
ppiCY = pvwprgCY - thicknessx2;
|
2018-12-16 16:14:58 +00:00
|
|
|
ppiScaleX = (pvwprgCX - thicknessx2) / fw;
|
|
|
|
ppiScaleY = (pvwprgCY - thicknessx2) / fh;
|
|
|
|
|
|
|
|
scenesCX = pvwprgCX / 2;
|
|
|
|
scenesCY = pvwprgCY / 2;
|
2019-09-22 21:19:10 +00:00
|
|
|
siCX = scenesCX - thicknessx2;
|
|
|
|
siCY = scenesCY - thicknessx2;
|
|
|
|
siScaleX = (scenesCX - thicknessx2) / fw;
|
|
|
|
siScaleY = (scenesCY - thicknessx2) / fh;
|
2018-12-16 16:14:58 +00:00
|
|
|
|
|
|
|
numSrcs = 0;
|
|
|
|
size_t i = 0;
|
|
|
|
while (i < scenes.sources.num && numSrcs < maxSrcs) {
|
|
|
|
obs_source_t *src = scenes.sources.array[i++];
|
2018-02-19 19:54:37 +00:00
|
|
|
OBSData data = obs_source_get_private_settings(src);
|
|
|
|
obs_data_release(data);
|
|
|
|
|
|
|
|
obs_data_set_default_bool(data, "show_in_multiview", true);
|
|
|
|
if (!obs_data_get_bool(data, "show_in_multiview"))
|
|
|
|
continue;
|
|
|
|
|
2018-12-16 16:14:58 +00:00
|
|
|
// We have a displayable source.
|
|
|
|
numSrcs++;
|
|
|
|
|
|
|
|
multiviewScenes.emplace_back(OBSGetWeakRef(src));
|
2018-02-19 19:54:37 +00:00
|
|
|
obs_source_inc_showing(src);
|
|
|
|
|
2018-12-16 16:14:58 +00:00
|
|
|
std::string name = std::to_string(numSrcs) + " - " +
|
2019-09-22 21:19:10 +00:00
|
|
|
obs_source_get_name(src);
|
2018-12-16 16:14:58 +00:00
|
|
|
multiviewLabels.emplace_back(CreateLabel(name.c_str(), h / 3));
|
|
|
|
}
|
2018-02-19 19:54:37 +00:00
|
|
|
|
2018-12-16 16:14:58 +00:00
|
|
|
obs_frontend_source_list_free(&scenes);
|
|
|
|
}
|
2018-02-19 19:54:37 +00:00
|
|
|
|
2018-12-16 16:14:58 +00:00
|
|
|
void OBSProjector::UpdateProjectorTitle(QString name)
|
|
|
|
{
|
2020-03-25 08:07:22 +00:00
|
|
|
bool window = (GetMonitor() == -1);
|
2018-12-16 16:14:58 +00:00
|
|
|
|
|
|
|
QString title = nullptr;
|
|
|
|
switch (type) {
|
|
|
|
case ProjectorType::Scene:
|
2020-03-25 08:07:22 +00:00
|
|
|
if (!window)
|
|
|
|
title = QTStr("SceneProjector") + " - " + name;
|
|
|
|
else
|
|
|
|
title = QTStr("SceneWindow") + " - " + name;
|
2018-12-16 16:14:58 +00:00
|
|
|
break;
|
|
|
|
case ProjectorType::Source:
|
2020-03-25 08:07:22 +00:00
|
|
|
if (!window)
|
|
|
|
title = QTStr("SourceProjector") + " - " + name;
|
|
|
|
else
|
|
|
|
title = QTStr("SourceWindow") + " - " + name;
|
|
|
|
break;
|
|
|
|
case ProjectorType::Preview:
|
|
|
|
if (!window)
|
|
|
|
title = QTStr("PreviewProjector");
|
|
|
|
else
|
|
|
|
title = QTStr("PreviewWindow");
|
|
|
|
break;
|
|
|
|
case ProjectorType::StudioProgram:
|
|
|
|
if (!window)
|
|
|
|
title = QTStr("StudioProgramProjector");
|
|
|
|
else
|
|
|
|
title = QTStr("StudioProgramWindow");
|
|
|
|
break;
|
|
|
|
case ProjectorType::Multiview:
|
|
|
|
if (!window)
|
|
|
|
title = QTStr("MultiviewProjector");
|
|
|
|
else
|
|
|
|
title = QTStr("MultiviewWindowed");
|
2018-12-16 16:14:58 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
title = name;
|
|
|
|
break;
|
2018-02-19 19:54:37 +00:00
|
|
|
}
|
|
|
|
|
2018-12-16 16:14:58 +00:00
|
|
|
setWindowTitle(title);
|
|
|
|
}
|
2018-02-19 19:54:37 +00:00
|
|
|
|
2018-12-16 16:14:58 +00:00
|
|
|
OBSSource OBSProjector::GetSource()
|
|
|
|
{
|
|
|
|
return source;
|
|
|
|
}
|
2018-02-19 19:54:37 +00:00
|
|
|
|
2018-12-16 16:14:58 +00:00
|
|
|
ProjectorType OBSProjector::GetProjectorType()
|
|
|
|
{
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
int OBSProjector::GetMonitor()
|
|
|
|
{
|
|
|
|
return savedMonitor;
|
2018-02-19 19:54:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OBSProjector::UpdateMultiviewProjectors()
|
|
|
|
{
|
|
|
|
obs_enter_graphics();
|
|
|
|
updatingMultiview = true;
|
|
|
|
obs_leave_graphics();
|
|
|
|
|
|
|
|
for (auto &projector : multiviewProjectors)
|
|
|
|
projector->UpdateMultiview();
|
|
|
|
|
|
|
|
obs_enter_graphics();
|
|
|
|
updatingMultiview = false;
|
|
|
|
obs_leave_graphics();
|
|
|
|
}
|
2018-12-16 16:14:58 +00:00
|
|
|
|
|
|
|
void OBSProjector::RenameProjector(QString oldName, QString newName)
|
|
|
|
{
|
2020-03-25 08:07:22 +00:00
|
|
|
if (oldName == newName)
|
|
|
|
return;
|
|
|
|
|
|
|
|
UpdateProjectorTitle(newName);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OBSProjector::OpenFullScreenProjector()
|
|
|
|
{
|
|
|
|
if (!isFullScreen())
|
|
|
|
prevGeometry = geometry();
|
|
|
|
|
|
|
|
int monitor = sender()->property("monitor").toInt();
|
|
|
|
SetMonitor(monitor);
|
|
|
|
|
|
|
|
UpdateProjectorTitle(QT_UTF8(obs_source_get_name(source)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void OBSProjector::OpenWindowedProjector()
|
|
|
|
{
|
|
|
|
showFullScreen();
|
|
|
|
showNormal();
|
|
|
|
setCursor(Qt::ArrowCursor);
|
|
|
|
|
|
|
|
if (!prevGeometry.isNull())
|
|
|
|
setGeometry(prevGeometry);
|
|
|
|
else
|
|
|
|
resize(480, 270);
|
|
|
|
|
|
|
|
savedMonitor = -1;
|
|
|
|
|
|
|
|
UpdateProjectorTitle(QT_UTF8(obs_source_get_name(source)));
|
2020-10-01 20:15:25 +00:00
|
|
|
screen = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OBSProjector::ResizeToContent()
|
|
|
|
{
|
|
|
|
OBSSource source = GetSource();
|
|
|
|
uint32_t targetCX;
|
|
|
|
uint32_t targetCY;
|
|
|
|
int x, y, newX, newY;
|
|
|
|
float scale;
|
|
|
|
|
|
|
|
if (source) {
|
|
|
|
targetCX = std::max(obs_source_get_width(source), 1u);
|
|
|
|
targetCY = std::max(obs_source_get_height(source), 1u);
|
|
|
|
} else {
|
|
|
|
struct obs_video_info ovi;
|
|
|
|
obs_get_video_info(&ovi);
|
|
|
|
targetCX = ovi.base_width;
|
|
|
|
targetCY = ovi.base_height;
|
|
|
|
}
|
|
|
|
|
|
|
|
QSize size = this->size();
|
|
|
|
GetScaleAndCenterPos(targetCX, targetCY, size.width(), size.height(), x,
|
|
|
|
y, scale);
|
|
|
|
|
|
|
|
newX = size.width() - (x * 2);
|
|
|
|
newY = size.height() - (y * 2);
|
|
|
|
resize(newX, newY);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OBSProjector::AlwaysOnTopToggled(bool isAlwaysOnTop)
|
|
|
|
{
|
|
|
|
SetIsAlwaysOnTop(isAlwaysOnTop, true);
|
2020-03-25 08:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OBSProjector::closeEvent(QCloseEvent *event)
|
|
|
|
{
|
|
|
|
EscapeTriggered();
|
|
|
|
event->accept();
|
2018-12-16 16:14:58 +00:00
|
|
|
}
|
2020-10-01 20:15:25 +00:00
|
|
|
|
|
|
|
bool OBSProjector::IsAlwaysOnTop() const
|
|
|
|
{
|
|
|
|
return isAlwaysOnTop;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OBSProjector::IsAlwaysOnTopOverridden() const
|
|
|
|
{
|
|
|
|
return isAlwaysOnTopOverridden;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OBSProjector::SetIsAlwaysOnTop(bool isAlwaysOnTop, bool isOverridden)
|
|
|
|
{
|
|
|
|
this->isAlwaysOnTop = isAlwaysOnTop;
|
|
|
|
this->isAlwaysOnTopOverridden = isOverridden;
|
|
|
|
|
|
|
|
SetAlwaysOnTop(this, isAlwaysOnTop);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OBSProjector::ScreenRemoved(QScreen *screen_)
|
|
|
|
{
|
|
|
|
if (GetMonitor() < 0 || !screen)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (screen == screen_)
|
|
|
|
EscapeTriggered();
|
|
|
|
}
|