2015-04-04 00:37:02 -07:00
|
|
|
#include <QAction>
|
2016-10-03 23:50:13 -07:00
|
|
|
#include <QGuiApplication>
|
2015-04-13 14:31:36 -07:00
|
|
|
#include <QMouseEvent>
|
|
|
|
#include <QMenu>
|
2016-10-03 23:50:13 -07:00
|
|
|
#include <QScreen>
|
2018-02-28 16:43:07 -08:00
|
|
|
#include "obs-app.hpp"
|
2018-02-27 19:57:54 -08:00
|
|
|
#include "window-basic-main.hpp"
|
2015-04-04 00:37:02 -07:00
|
|
|
#include "display-helpers.hpp"
|
|
|
|
#include "qt-wrappers.hpp"
|
|
|
|
#include "platform.hpp"
|
2017-10-21 10:51:01 -07:00
|
|
|
|
|
|
|
static QList<OBSProjector *> multiviewProjectors;
|
2018-03-19 19:27:44 -07:00
|
|
|
static bool updatingMultiview = false, drawLabel, drawSafeArea, mouseSwitching,
|
2019-06-22 22:13:45 -07:00
|
|
|
transitionOnDoubleClick;
|
2018-03-07 01:12:55 -08:00
|
|
|
static MultiviewLayout multiviewLayout;
|
2018-03-20 20:16:42 -07:00
|
|
|
static size_t maxSrcs, numSrcs;
|
2015-04-04 00:37:02 -07:00
|
|
|
|
2018-02-28 18:34:11 -08:00
|
|
|
OBSProjector::OBSProjector(QWidget *widget, obs_source_t *source_, int monitor,
|
2019-10-07 22:43:10 -07:00
|
|
|
ProjectorType type_)
|
2019-06-22 22:13:45 -07:00
|
|
|
: OBSQTDisplay(widget, Qt::Window),
|
|
|
|
source(source_),
|
|
|
|
removedSignal(obs_source_get_signal_handler(source), "remove",
|
|
|
|
OBSSourceRemoved, this)
|
2015-04-04 00:37:02 -07:00
|
|
|
{
|
2019-06-22 22:13:45 -07:00
|
|
|
type = type_;
|
2018-02-28 18:34:11 -08:00
|
|
|
|
2019-10-07 22:43:10 -07:00
|
|
|
setWindowIcon(QIcon::fromTheme("obs", QIcon(":/res/images/obs.png")));
|
|
|
|
UpdateProjectorTitle(QT_UTF8(obs_source_get_name(source)));
|
2018-04-29 05:29:53 -07:00
|
|
|
|
2019-10-07 22:43:10 -07:00
|
|
|
if (monitor == -1)
|
2018-04-29 05:29:53 -07:00
|
|
|
resize(480, 270);
|
2019-10-07 22:43:10 -07:00
|
|
|
else
|
|
|
|
SetMonitor(monitor);
|
2018-04-29 05:29:53 -07:00
|
|
|
|
2019-10-07 22:43:10 -07:00
|
|
|
QAction *action = new QAction(this);
|
|
|
|
action->setShortcut(Qt::Key_Escape);
|
|
|
|
addAction(action);
|
|
|
|
connect(action, SIGNAL(triggered()), this, SLOT(EscapeTriggered()));
|
2017-03-01 20:08:49 -08:00
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
SetAlwaysOnTop(this, config_get_bool(GetGlobalConfig(), "BasicWindow",
|
|
|
|
"ProjectorAlwaysOnTop"));
|
2018-09-04 19:29:37 -07:00
|
|
|
|
2015-04-04 00:37:02 -07:00
|
|
|
setAttribute(Qt::WA_DeleteOnClose, true);
|
2014-11-01 13:48:58 -07:00
|
|
|
|
2017-01-25 12:46:41 -08:00
|
|
|
//disable application quit when last window closed
|
|
|
|
setAttribute(Qt::WA_QuitOnClose, false);
|
|
|
|
|
2014-11-01 13:48:58 -07:00
|
|
|
installEventFilter(CreateShortcutFilter());
|
2015-08-02 00:25:08 -07:00
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
auto addDrawCallback = [this]() {
|
2017-10-21 10:51:01 -07:00
|
|
|
bool isMultiview = type == ProjectorType::Multiview;
|
2019-06-22 22:13:45 -07:00
|
|
|
obs_display_add_draw_callback(
|
|
|
|
GetDisplay(),
|
|
|
|
isMultiview ? OBSRenderMultiview : OBSRender, this);
|
2019-06-16 17:42:02 -07:00
|
|
|
obs_display_set_background_color(GetDisplay(), 0x000000);
|
2015-08-02 00:25:08 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
connect(this, &OBSQTDisplay::DisplayCreated, addDrawCallback);
|
2015-11-16 09:08:55 -08:00
|
|
|
|
2019-10-07 22:43:10 -07:00
|
|
|
if (isFullScreen())
|
|
|
|
SetHideCursor();
|
2016-06-27 14:47:42 -07:00
|
|
|
|
2018-02-28 18:34:11 -08:00
|
|
|
if (type == ProjectorType::Multiview) {
|
|
|
|
obs_enter_graphics();
|
|
|
|
|
2018-03-18 18:00:18 -07:00
|
|
|
// All essential action should be placed inside this area
|
2018-02-28 18:34:11 -08:00
|
|
|
gs_render_start(true);
|
2018-03-18 18:00:18 -07:00
|
|
|
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
|
2018-02-28 18:34:11 -08:00
|
|
|
gs_render_start(true);
|
2018-03-18 18:00:18 -07:00
|
|
|
gs_vertex2f(graphicsSafePercentage, graphicsSafePercentage);
|
|
|
|
gs_vertex2f(graphicsSafePercentage, 1 - graphicsSafePercentage);
|
|
|
|
gs_vertex2f(1 - graphicsSafePercentage,
|
2019-06-22 22:13:45 -07:00
|
|
|
1 - graphicsSafePercentage);
|
2018-03-18 18:00:18 -07:00
|
|
|
gs_vertex2f(1 - graphicsSafePercentage, graphicsSafePercentage);
|
|
|
|
gs_vertex2f(graphicsSafePercentage, graphicsSafePercentage);
|
|
|
|
graphicsSafeMargin = gs_render_save();
|
|
|
|
|
|
|
|
// 4:3 safe area for widescreen
|
2018-02-28 18:34:11 -08:00
|
|
|
gs_render_start(true);
|
2018-03-18 18:00:18 -07:00
|
|
|
gs_vertex2f(fourByThreeSafePercentage, graphicsSafePercentage);
|
|
|
|
gs_vertex2f(1 - fourByThreeSafePercentage,
|
2019-06-22 22:13:45 -07:00
|
|
|
graphicsSafePercentage);
|
|
|
|
gs_vertex2f(1 - fourByThreeSafePercentage,
|
|
|
|
1 - graphicsSafePercentage);
|
2018-03-18 18:00:18 -07:00
|
|
|
gs_vertex2f(fourByThreeSafePercentage,
|
2019-06-22 22:13:45 -07:00
|
|
|
1 - graphicsSafePercentage);
|
2018-03-18 18:00:18 -07:00
|
|
|
gs_vertex2f(fourByThreeSafePercentage, graphicsSafePercentage);
|
|
|
|
fourByThreeSafeMargin = gs_render_save();
|
2018-02-28 18:34:11 -08:00
|
|
|
|
|
|
|
gs_render_start(true);
|
|
|
|
gs_vertex2f(0.0f, 0.5f);
|
2018-03-18 18:00:18 -07:00
|
|
|
gs_vertex2f(lineLength, 0.5f);
|
2018-02-28 18:34:11 -08:00
|
|
|
leftLine = gs_render_save();
|
|
|
|
|
|
|
|
gs_render_start(true);
|
|
|
|
gs_vertex2f(0.5f, 0.0f);
|
2018-03-18 18:00:18 -07:00
|
|
|
gs_vertex2f(0.5f, lineLength);
|
2018-02-28 18:34:11 -08:00
|
|
|
topLine = gs_render_save();
|
|
|
|
|
|
|
|
gs_render_start(true);
|
|
|
|
gs_vertex2f(1.0f, 0.5f);
|
2018-03-18 18:00:18 -07:00
|
|
|
gs_vertex2f(1 - lineLength, 0.5f);
|
2018-02-28 18:34:11 -08:00
|
|
|
rightLine = gs_render_save();
|
|
|
|
obs_leave_graphics();
|
|
|
|
|
2018-03-19 23:20:45 -07:00
|
|
|
solid = obs_get_base_effect(OBS_EFFECT_SOLID);
|
|
|
|
color = gs_effect_get_param_by_name(solid, "color");
|
|
|
|
|
2018-02-28 18:34:11 -08:00
|
|
|
UpdateMultiview();
|
|
|
|
|
|
|
|
multiviewProjectors.push_back(this);
|
|
|
|
}
|
|
|
|
|
2015-11-16 09:08:55 -08:00
|
|
|
App()->IncrementSleepInhibition();
|
2018-04-29 05:29:53 -07:00
|
|
|
|
|
|
|
if (source)
|
|
|
|
obs_source_inc_showing(source);
|
|
|
|
|
|
|
|
ready = true;
|
|
|
|
|
|
|
|
show();
|
|
|
|
|
|
|
|
// We need it here to allow keyboard input in X11 to listen to Escape
|
2019-10-07 22:43:10 -07:00
|
|
|
activateWindow();
|
2015-04-04 00:37:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
OBSProjector::~OBSProjector()
|
|
|
|
{
|
2017-10-21 10:51:01 -07:00
|
|
|
bool isMultiview = type == ProjectorType::Multiview;
|
2019-06-22 22:13:45 -07:00
|
|
|
obs_display_remove_draw_callback(
|
|
|
|
GetDisplay(), isMultiview ? OBSRenderMultiview : OBSRender,
|
|
|
|
this);
|
2017-10-21 10:51:01 -07:00
|
|
|
|
2015-04-04 00:37:02 -07:00
|
|
|
if (source)
|
|
|
|
obs_source_dec_showing(source);
|
2017-10-21 10:51:01 -07:00
|
|
|
|
|
|
|
if (isMultiview) {
|
|
|
|
for (OBSWeakSource &weakSrc : multiviewScenes) {
|
|
|
|
OBSSource src = OBSGetStrongRef(weakSrc);
|
|
|
|
if (src)
|
|
|
|
obs_source_dec_showing(src);
|
|
|
|
}
|
|
|
|
|
|
|
|
obs_enter_graphics();
|
2018-03-18 18:00:18 -07:00
|
|
|
gs_vertexbuffer_destroy(actionSafeMargin);
|
|
|
|
gs_vertexbuffer_destroy(graphicsSafeMargin);
|
|
|
|
gs_vertexbuffer_destroy(fourByThreeSafeMargin);
|
2017-10-21 10:51:01 -07:00
|
|
|
gs_vertexbuffer_destroy(leftLine);
|
|
|
|
gs_vertexbuffer_destroy(topLine);
|
|
|
|
gs_vertexbuffer_destroy(rightLine);
|
|
|
|
obs_leave_graphics();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == ProjectorType::Multiview)
|
|
|
|
multiviewProjectors.removeAll(this);
|
|
|
|
|
2015-11-16 09:08:55 -08:00
|
|
|
App()->DecrementSleepInhibition();
|
2015-04-04 00:37:02 -07:00
|
|
|
}
|
|
|
|
|
2019-10-07 22:43:10 -07:00
|
|
|
void OBSProjector::SetMonitor(int monitor)
|
|
|
|
{
|
|
|
|
savedMonitor = monitor;
|
|
|
|
QScreen *screen = QGuiApplication::screens()[monitor];
|
|
|
|
showFullScreen();
|
|
|
|
setGeometry(screen->geometry());
|
|
|
|
}
|
|
|
|
|
|
|
|
void OBSProjector::SetHideCursor()
|
|
|
|
{
|
|
|
|
bool hideCursor = config_get_bool(GetGlobalConfig(), "BasicWindow",
|
|
|
|
"HideProjectorCursor");
|
|
|
|
|
|
|
|
if (hideCursor && type != ProjectorType::Multiview)
|
|
|
|
setCursor(Qt::BlankCursor);
|
|
|
|
else
|
|
|
|
setCursor(Qt::ArrowCursor);
|
|
|
|
}
|
|
|
|
|
2017-10-21 10:51:01 -07:00
|
|
|
static OBSSource CreateLabel(const char *name, size_t h)
|
|
|
|
{
|
|
|
|
obs_data_t *settings = obs_data_create();
|
2019-06-22 22:13:45 -07:00
|
|
|
obs_data_t *font = obs_data_create();
|
2017-10-21 10:51:01 -07: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
|
2018-01-22 05:00:41 -08:00
|
|
|
obs_data_set_int(font, "flags", 1); // Bold text
|
2017-10-21 10:51:01 -07:00
|
|
|
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());
|
2018-01-22 05:00:41 -08:00
|
|
|
obs_data_set_bool(settings, "outline", false);
|
2017-10-21 10:51:01 -07:00
|
|
|
|
2018-01-10 21:36:17 -08:00
|
|
|
#ifdef _WIN32
|
|
|
|
const char *text_source_id = "text_gdiplus";
|
|
|
|
#else
|
|
|
|
const char *text_source_id = "text_ft2_source";
|
|
|
|
#endif
|
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
OBSSource txtSource =
|
|
|
|
obs_source_create_private(text_source_id, name, settings);
|
2017-10-21 10:51:01 -07: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-03-14 01:27:03 -07:00
|
|
|
|
|
|
|
int n; // Number of scenes per row
|
|
|
|
switch (multiviewLayout) {
|
2018-03-22 20:57:15 -07:00
|
|
|
case MultiviewLayout::HORIZONTAL_TOP_24_SCENES:
|
|
|
|
n = 6;
|
|
|
|
break;
|
2018-03-14 01:27:03 -07:00
|
|
|
default:
|
|
|
|
n = 4;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
w = uint32_t(w * ((1.0f) / n));
|
2017-10-21 10:51:01 -07:00
|
|
|
return (cx / 2) - w;
|
|
|
|
}
|
|
|
|
|
2018-03-08 15:27:15 -08:00
|
|
|
static inline void startRegion(int vX, int vY, int vCX, int vCY, float oL,
|
2019-06-22 22:13:45 -07:00
|
|
|
float oR, float oT, float oB)
|
2018-03-08 15:27:15 -08: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();
|
|
|
|
}
|
|
|
|
|
2017-10-21 10:51:01 -07:00
|
|
|
void OBSProjector::OBSRenderMultiview(void *data, uint32_t cx, uint32_t cy)
|
|
|
|
{
|
|
|
|
OBSProjector *window = (OBSProjector *)data;
|
|
|
|
|
|
|
|
if (updatingMultiview || !window->ready)
|
|
|
|
return;
|
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
OBSBasic *main = (OBSBasic *)obs_frontend_get_main_window();
|
|
|
|
uint32_t targetCX, targetCY;
|
|
|
|
int x, y;
|
|
|
|
float scale;
|
2017-10-21 10:51:01 -07:00
|
|
|
|
2018-03-22 18:07:59 -07:00
|
|
|
targetCX = (uint32_t)window->fw;
|
|
|
|
targetCY = (uint32_t)window->fh;
|
2017-10-21 10:51:01 -07:00
|
|
|
|
2018-03-19 23:20:45 -07:00
|
|
|
GetScaleAndCenterPos(targetCX, targetCY, cx, cy, x, y, scale);
|
2017-10-21 10:51:01 -07:00
|
|
|
|
|
|
|
OBSSource previewSrc = main->GetCurrentSceneSource();
|
|
|
|
OBSSource programSrc = main->GetProgramSource();
|
|
|
|
bool studioMode = main->IsPreviewProgramMode();
|
|
|
|
|
2018-03-19 23:20:45 -07:00
|
|
|
auto renderVB = [&](gs_vertbuffer_t *vb, int cx, int cy,
|
2019-06-22 22:13:45 -07:00
|
|
|
uint32_t colorVal) {
|
2018-03-11 22:29:00 -07: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);
|
|
|
|
|
2018-03-19 23:20:45 -07:00
|
|
|
gs_effect_set_color(window->color, colorVal);
|
|
|
|
while (gs_effect_loop(window->solid, "Solid"))
|
2018-03-11 22:29:00 -07:00
|
|
|
gs_draw(GS_LINESTRIP, 0, 0);
|
|
|
|
|
|
|
|
gs_matrix_pop();
|
|
|
|
};
|
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
auto drawBox = [&](float cx, float cy, uint32_t colorVal) {
|
2018-03-19 23:20:45 -07:00
|
|
|
gs_effect_set_color(window->color, colorVal);
|
|
|
|
while (gs_effect_loop(window->solid, "Solid"))
|
2017-10-21 10:51:01 -07:00
|
|
|
gs_draw_sprite(nullptr, 0, (uint32_t)cx, (uint32_t)cy);
|
|
|
|
};
|
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
auto setRegion = [&](float bx, float by, float cx, float cy) {
|
|
|
|
float vX = int(x + bx * scale);
|
|
|
|
float vY = int(y + by * scale);
|
2017-12-02 15:36:32 -08:00
|
|
|
float vCX = int(cx * scale);
|
|
|
|
float vCY = int(cy * scale);
|
|
|
|
|
2018-03-19 23:20:45 -07:00
|
|
|
float oL = bx;
|
|
|
|
float oT = by;
|
|
|
|
float oR = (bx + cx);
|
|
|
|
float oB = (by + cy);
|
2017-12-02 15:36:32 -08:00
|
|
|
|
2018-03-08 15:27:15 -08:00
|
|
|
startRegion(vX, vY, vCX, vCY, oL, oR, oT, oB);
|
2017-12-02 15:36:32 -08:00
|
|
|
};
|
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
auto calcBaseSource = [&](size_t i) {
|
2017-12-13 13:42:19 -08:00
|
|
|
switch (multiviewLayout) {
|
2018-03-22 20:57:15 -07:00
|
|
|
case MultiviewLayout::HORIZONTAL_TOP_24_SCENES:
|
|
|
|
window->sourceX = (i % 6) * window->scenesCX;
|
2019-06-22 22:13:45 -07:00
|
|
|
window->sourceY =
|
|
|
|
window->pvwprgCY + (i / 6) * window->scenesCY;
|
2018-03-22 20:57:15 -07:00
|
|
|
break;
|
2018-03-20 17:41:39 -07:00
|
|
|
case MultiviewLayout::VERTICAL_LEFT_8_SCENES:
|
2018-03-22 20:57:15 -07:00
|
|
|
window->sourceX = window->pvwprgCX;
|
2019-06-22 22:13:45 -07:00
|
|
|
window->sourceY = (i / 2) * window->scenesCY;
|
2017-12-13 13:42:19 -08:00
|
|
|
if (i % 2 != 0)
|
2018-03-22 20:57:15 -07:00
|
|
|
window->sourceX += window->scenesCX;
|
2017-12-13 13:42:19 -08:00
|
|
|
break;
|
2018-03-20 17:41:39 -07:00
|
|
|
case MultiviewLayout::VERTICAL_RIGHT_8_SCENES:
|
2018-03-19 23:20:45 -07:00
|
|
|
window->sourceX = 0;
|
2019-06-22 22:13:45 -07:00
|
|
|
window->sourceY = (i / 2) * window->scenesCY;
|
2017-12-13 13:42:19 -08:00
|
|
|
if (i % 2 != 0)
|
2018-03-22 20:57:15 -07:00
|
|
|
window->sourceX = window->scenesCX;
|
2017-12-13 13:42:19 -08:00
|
|
|
break;
|
2018-03-20 17:41:39 -07:00
|
|
|
case MultiviewLayout::HORIZONTAL_BOTTOM_8_SCENES:
|
2017-12-13 13:42:19 -08:00
|
|
|
if (i < 4) {
|
2018-03-22 20:57:15 -07:00
|
|
|
window->sourceX = (float(i) * window->scenesCX);
|
2018-03-19 23:20:45 -07:00
|
|
|
window->sourceY = 0;
|
2017-12-13 13:42:19 -08:00
|
|
|
} else {
|
2019-06-22 22:13:45 -07:00
|
|
|
window->sourceX =
|
|
|
|
(float(i - 4) * window->scenesCX);
|
2018-03-22 20:57:15 -07:00
|
|
|
window->sourceY = window->scenesCY;
|
2017-12-13 13:42:19 -08:00
|
|
|
}
|
|
|
|
break;
|
2018-03-20 17:41:39 -07:00
|
|
|
default: // MultiviewLayout::HORIZONTAL_TOP_8_SCENES:
|
2017-12-13 13:42:19 -08:00
|
|
|
if (i < 4) {
|
2018-03-22 20:57:15 -07:00
|
|
|
window->sourceX = (float(i) * window->scenesCX);
|
|
|
|
window->sourceY = window->pvwprgCY;
|
2017-12-13 13:42:19 -08:00
|
|
|
} else {
|
2019-06-22 22:13:45 -07:00
|
|
|
window->sourceX =
|
|
|
|
(float(i - 4) * window->scenesCX);
|
|
|
|
window->sourceY =
|
|
|
|
window->pvwprgCY + window->scenesCY;
|
2017-12-13 13:42:19 -08:00
|
|
|
}
|
|
|
|
}
|
2018-03-22 20:57:15 -07:00
|
|
|
window->siX = window->sourceX + window->thickness;
|
|
|
|
window->siY = window->sourceY + window->thickness;
|
2017-12-13 13:42:19 -08:00
|
|
|
};
|
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
auto calcPreviewProgram = [&](bool program) {
|
2017-12-13 13:42:19 -08:00
|
|
|
switch (multiviewLayout) {
|
2018-03-22 20:57:15 -07:00
|
|
|
case MultiviewLayout::HORIZONTAL_TOP_24_SCENES:
|
2019-06-22 22:13:45 -07:00
|
|
|
window->sourceX =
|
|
|
|
window->thickness + window->pvwprgCX / 2;
|
2018-03-22 20:57:15 -07: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;
|
2018-03-20 17:41:39 -07:00
|
|
|
case MultiviewLayout::VERTICAL_LEFT_8_SCENES:
|
2018-03-19 23:20:45 -07:00
|
|
|
window->sourceX = window->thickness;
|
2018-03-22 20:57:15 -07:00
|
|
|
window->sourceY = window->pvwprgCY + window->thickness;
|
2018-03-19 23:20:45 -07:00
|
|
|
window->labelX = window->offset;
|
2018-03-22 20:57:15 -07:00
|
|
|
window->labelY = window->pvwprgCY * 1.85f;
|
2017-12-13 13:42:19 -08:00
|
|
|
if (program) {
|
2018-03-19 23:20:45 -07:00
|
|
|
window->sourceY = window->thickness;
|
2018-03-22 20:57:15 -07:00
|
|
|
window->labelY = window->pvwprgCY * 0.85f;
|
2017-12-13 13:42:19 -08:00
|
|
|
}
|
|
|
|
break;
|
2018-03-20 17:41:39 -07:00
|
|
|
case MultiviewLayout::VERTICAL_RIGHT_8_SCENES:
|
2018-03-22 20:57:15 -07:00
|
|
|
window->sourceX = window->pvwprgCX + window->thickness;
|
|
|
|
window->sourceY = window->pvwprgCY + window->thickness;
|
|
|
|
window->labelX = window->pvwprgCX + window->offset;
|
|
|
|
window->labelY = window->pvwprgCY * 1.85f;
|
2017-12-13 13:42:19 -08:00
|
|
|
if (program) {
|
2018-03-19 23:20:45 -07:00
|
|
|
window->sourceY = window->thickness;
|
2018-03-22 20:57:15 -07:00
|
|
|
window->labelY = window->pvwprgCY * 0.85f;
|
2017-12-13 13:42:19 -08:00
|
|
|
}
|
|
|
|
break;
|
2018-03-20 17:41:39 -07:00
|
|
|
case MultiviewLayout::HORIZONTAL_BOTTOM_8_SCENES:
|
2018-03-19 23:20:45 -07:00
|
|
|
window->sourceX = window->thickness;
|
2018-03-22 20:57:15 -07:00
|
|
|
window->sourceY = window->pvwprgCY + window->thickness;
|
2018-03-19 23:20:45 -07:00
|
|
|
window->labelX = window->offset;
|
2018-03-22 20:57:15 -07:00
|
|
|
window->labelY = window->pvwprgCY * 1.85f;
|
2017-12-13 13:42:19 -08:00
|
|
|
if (program) {
|
2018-03-22 20:57:15 -07:00
|
|
|
window->sourceX += window->pvwprgCX;
|
|
|
|
window->labelX += window->pvwprgCX;
|
2017-12-13 13:42:19 -08:00
|
|
|
}
|
|
|
|
break;
|
2018-03-20 17:41:39 -07:00
|
|
|
default: // MultiviewLayout::HORIZONTAL_TOP_8_SCENES:
|
2018-03-19 23:20:45 -07:00
|
|
|
window->sourceX = window->thickness;
|
|
|
|
window->sourceY = window->thickness;
|
|
|
|
window->labelX = window->offset;
|
2018-03-22 20:57:15 -07:00
|
|
|
window->labelY = window->pvwprgCY * 0.85f;
|
2017-12-13 13:42:19 -08:00
|
|
|
if (program) {
|
2018-03-22 20:57:15 -07:00
|
|
|
window->sourceX += window->pvwprgCX;
|
|
|
|
window->labelX += window->pvwprgCX;
|
2017-12-13 13:42:19 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-03-13 19:52:32 -07:00
|
|
|
auto paintAreaWithColor = [&](float tx, float ty, float cx, float cy,
|
2019-06-22 22:13:45 -07:00
|
|
|
uint32_t color) {
|
2018-03-13 19:52:32 -07:00
|
|
|
gs_matrix_push();
|
|
|
|
gs_matrix_translate3f(tx, ty, 0.0f);
|
|
|
|
drawBox(cx, cy, color);
|
|
|
|
gs_matrix_pop();
|
|
|
|
};
|
|
|
|
|
2018-03-13 10:33:14 -07:00
|
|
|
// Define the whole usable region for the multiview
|
2018-03-22 18:07:59 -07:00
|
|
|
startRegion(x, y, targetCX * scale, targetCY * scale, 0.0f, window->fw,
|
2019-06-22 22:13:45 -07:00
|
|
|
0.0f, window->fh);
|
2017-10-21 10:51:01 -07:00
|
|
|
|
2018-03-13 10:33:14 -07:00
|
|
|
// Change the background color to highlight all sources
|
2018-03-22 18:07:59 -07:00
|
|
|
drawBox(window->fw, window->fh, outerColor);
|
2018-03-13 10:33:14 -07:00
|
|
|
|
|
|
|
/* ----------------------------- */
|
|
|
|
/* draw sources */
|
|
|
|
|
2018-03-22 20:57:15 -07:00
|
|
|
for (size_t i = 0; i < maxSrcs; i++) {
|
2018-03-13 19:52:32 -07:00
|
|
|
// Handle all the offsets
|
2017-12-13 13:42:19 -08:00
|
|
|
calcBaseSource(i);
|
2017-10-21 10:51:01 -07:00
|
|
|
|
2018-03-22 20:57:15 -07:00
|
|
|
if (i >= numSrcs) {
|
2018-03-19 23:20:45 -07:00
|
|
|
// Just paint the background and continue
|
|
|
|
paintAreaWithColor(window->sourceX, window->sourceY,
|
2019-06-22 22:13:45 -07:00
|
|
|
window->scenesCX, window->scenesCY,
|
|
|
|
outerColor);
|
2018-03-22 20:57:15 -07:00
|
|
|
paintAreaWithColor(window->siX, window->siY,
|
2019-06-22 22:13:45 -07:00
|
|
|
window->siCX, window->siCY,
|
|
|
|
backgroundColor);
|
2018-03-19 23:20:45 -07:00
|
|
|
continue;
|
2018-03-13 19:52:32 -07:00
|
|
|
}
|
2018-03-19 23:20:45 -07:00
|
|
|
|
2018-03-22 20:57:15 -07:00
|
|
|
OBSSource src = OBSGetStrongRef(window->multiviewScenes[i]);
|
|
|
|
|
2018-03-19 23:20:45 -07: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;
|
|
|
|
|
|
|
|
// Paint the background
|
|
|
|
paintAreaWithColor(window->sourceX, window->sourceY,
|
2019-06-22 22:13:45 -07:00
|
|
|
window->scenesCX, window->scenesCY,
|
|
|
|
colorVal);
|
2018-03-22 20:57:15 -07:00
|
|
|
paintAreaWithColor(window->siX, window->siY, window->siCX,
|
2019-06-22 22:13:45 -07:00
|
|
|
window->siCY, backgroundColor);
|
2018-03-19 23:20:45 -07:00
|
|
|
|
|
|
|
/* ----------- */
|
|
|
|
|
|
|
|
// Render the source
|
|
|
|
gs_matrix_push();
|
2018-03-22 20:57:15 -07: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-03-19 23:20:45 -07:00
|
|
|
obs_source_video_render(src);
|
|
|
|
endRegion();
|
|
|
|
gs_matrix_pop();
|
|
|
|
|
|
|
|
/* ----------- */
|
|
|
|
|
|
|
|
// Render the label
|
|
|
|
if (!drawLabel)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
obs_source *label = window->multiviewLabels[i + 2];
|
|
|
|
if (!label)
|
|
|
|
continue;
|
|
|
|
|
2018-03-22 20:57:15 -07:00
|
|
|
window->offset = labelOffset(label, window->scenesCX);
|
2018-03-19 23:20:45 -07:00
|
|
|
|
|
|
|
gs_matrix_push();
|
2019-06-22 22:13:45 -07:00
|
|
|
gs_matrix_translate3f(
|
|
|
|
window->sourceX + window->offset,
|
|
|
|
(window->scenesCY * 0.85f) + window->sourceY, 0.0f);
|
2018-03-22 20:57:15 -07:00
|
|
|
gs_matrix_scale3f(window->ppiScaleX, window->ppiScaleY, 1.0f);
|
2018-03-19 23:20:45 -07:00
|
|
|
drawBox(obs_source_get_width(label),
|
2019-06-22 22:13:45 -07:00
|
|
|
obs_source_get_height(label) +
|
|
|
|
int(window->sourceY * 0.015f),
|
|
|
|
labelColor);
|
2018-03-19 23:20:45 -07:00
|
|
|
obs_source_video_render(label);
|
|
|
|
gs_matrix_pop();
|
2017-10-21 10:51:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------------------- */
|
|
|
|
/* draw preview */
|
|
|
|
|
2017-12-13 13:42:19 -08:00
|
|
|
obs_source_t *previewLabel = window->multiviewLabels[0];
|
2018-03-22 20:57:15 -07:00
|
|
|
window->offset = labelOffset(previewLabel, window->pvwprgCX);
|
2017-12-13 13:42:19 -08:00
|
|
|
calcPreviewProgram(false);
|
|
|
|
|
2018-03-13 19:52:32 -07:00
|
|
|
// Paint the background
|
2018-03-22 20:57:15 -07:00
|
|
|
paintAreaWithColor(window->sourceX, window->sourceY, window->ppiCX,
|
2019-06-22 22:13:45 -07:00
|
|
|
window->ppiCY, backgroundColor);
|
2018-03-13 19:52:32 -07:00
|
|
|
|
|
|
|
// Scale and Draw the preview
|
2017-10-21 10:51:01 -07:00
|
|
|
gs_matrix_push();
|
2018-03-19 23:20:45 -07:00
|
|
|
gs_matrix_translate3f(window->sourceX, window->sourceY, 0.0f);
|
2018-03-22 20:57:15 -07:00
|
|
|
gs_matrix_scale3f(window->ppiScaleX, window->ppiScaleY, 1.0f);
|
|
|
|
setRegion(window->sourceX, window->sourceY, window->ppiCX,
|
2019-06-22 22:13:45 -07:00
|
|
|
window->ppiCY);
|
2018-03-13 19:52:32 -07:00
|
|
|
if (studioMode)
|
2017-10-21 10:51:01 -07:00
|
|
|
obs_source_video_render(previewSrc);
|
2018-03-13 19:52:32 -07:00
|
|
|
else
|
2018-01-01 18:33:44 -08:00
|
|
|
obs_render_main_texture();
|
2018-03-19 19:27:44 -07:00
|
|
|
if (drawSafeArea) {
|
2018-03-18 19:02:27 -07:00
|
|
|
renderVB(window->actionSafeMargin, targetCX, targetCY,
|
2019-06-22 22:13:45 -07:00
|
|
|
outerColor);
|
2018-03-18 19:02:27 -07:00
|
|
|
renderVB(window->graphicsSafeMargin, targetCX, targetCY,
|
2019-06-22 22:13:45 -07:00
|
|
|
outerColor);
|
2018-03-18 19:02:27 -07:00
|
|
|
renderVB(window->fourByThreeSafeMargin, targetCX, targetCY,
|
2019-06-22 22:13:45 -07:00
|
|
|
outerColor);
|
2018-03-18 19:02:27 -07:00
|
|
|
renderVB(window->leftLine, targetCX, targetCY, outerColor);
|
|
|
|
renderVB(window->topLine, targetCX, targetCY, outerColor);
|
|
|
|
renderVB(window->rightLine, targetCX, targetCY, outerColor);
|
|
|
|
}
|
2018-03-13 19:52:32 -07:00
|
|
|
endRegion();
|
2017-10-21 10:51:01 -07:00
|
|
|
gs_matrix_pop();
|
|
|
|
|
|
|
|
/* ----------- */
|
|
|
|
|
2018-03-13 19:52:32 -07:00
|
|
|
// Draw the Label
|
2018-03-19 19:27:44 -07:00
|
|
|
if (drawLabel) {
|
2018-03-16 19:00:32 -07:00
|
|
|
gs_matrix_push();
|
2018-03-19 23:20:45 -07:00
|
|
|
gs_matrix_translate3f(window->labelX, window->labelY, 0.0f);
|
2018-03-22 20:57:15 -07:00
|
|
|
gs_matrix_scale3f(window->ppiScaleX, window->ppiScaleY, 1.0f);
|
2018-03-16 19:00:32 -07:00
|
|
|
drawBox(obs_source_get_width(previewLabel),
|
2019-06-22 22:13:45 -07:00
|
|
|
obs_source_get_height(previewLabel) +
|
|
|
|
int(window->pvwprgCX * 0.015f),
|
|
|
|
labelColor);
|
2018-03-16 19:00:32 -07:00
|
|
|
obs_source_video_render(previewLabel);
|
|
|
|
gs_matrix_pop();
|
|
|
|
}
|
2017-10-21 10:51:01 -07:00
|
|
|
|
|
|
|
/* ----------------------------- */
|
|
|
|
/* draw program */
|
|
|
|
|
2017-12-13 13:42:19 -08:00
|
|
|
obs_source_t *programLabel = window->multiviewLabels[1];
|
2018-03-22 20:57:15 -07:00
|
|
|
window->offset = labelOffset(programLabel, window->pvwprgCX);
|
2017-12-13 13:42:19 -08:00
|
|
|
calcPreviewProgram(true);
|
|
|
|
|
2019-02-02 06:42:12 -08:00
|
|
|
paintAreaWithColor(window->sourceX, window->sourceY, window->ppiCX,
|
2019-06-22 22:13:45 -07:00
|
|
|
window->ppiCY, backgroundColor);
|
2019-02-02 06:42:12 -08:00
|
|
|
|
2018-03-13 19:52:32 -07:00
|
|
|
// Scale and Draw the program
|
2017-10-21 10:51:01 -07:00
|
|
|
gs_matrix_push();
|
2018-03-19 23:20:45 -07:00
|
|
|
gs_matrix_translate3f(window->sourceX, window->sourceY, 0.0f);
|
2018-03-22 20:57:15 -07:00
|
|
|
gs_matrix_scale3f(window->ppiScaleX, window->ppiScaleY, 1.0f);
|
|
|
|
setRegion(window->sourceX, window->sourceY, window->ppiCX,
|
2019-06-22 22:13:45 -07:00
|
|
|
window->ppiCY);
|
2018-01-01 18:33:44 -08:00
|
|
|
obs_render_main_texture();
|
2018-03-08 15:27:15 -08:00
|
|
|
endRegion();
|
2017-10-21 10:51:01 -07:00
|
|
|
gs_matrix_pop();
|
|
|
|
|
|
|
|
/* ----------- */
|
|
|
|
|
2018-03-13 19:52:32 -07:00
|
|
|
// Draw the Label
|
2018-03-19 19:27:44 -07:00
|
|
|
if (drawLabel) {
|
2018-03-16 19:00:32 -07:00
|
|
|
gs_matrix_push();
|
2018-03-19 23:20:45 -07:00
|
|
|
gs_matrix_translate3f(window->labelX, window->labelY, 0.0f);
|
2018-03-22 20:57:15 -07:00
|
|
|
gs_matrix_scale3f(window->ppiScaleX, window->ppiScaleY, 1.0f);
|
2018-03-16 19:00:32 -07:00
|
|
|
drawBox(obs_source_get_width(programLabel),
|
2019-06-22 22:13:45 -07:00
|
|
|
obs_source_get_height(programLabel) +
|
|
|
|
int(window->pvwprgCX * 0.015f),
|
|
|
|
labelColor);
|
2018-03-16 19:00:32 -07:00
|
|
|
obs_source_video_render(programLabel);
|
|
|
|
gs_matrix_pop();
|
|
|
|
}
|
|
|
|
|
docs/sphinx: Fix various typos
(This modifies UI, libobs, deps/obs-scripting, various cmake files)
Found using:
`codespell -q 3 -S *.ini,./UI/data/locale,./deps/w32-pthreads -L aci,dur,iff,mut,numer,uint`
2019-09-19 04:31:17 -07:00
|
|
|
// Region for future usage with additional info.
|
2018-03-22 20:57:15 -07:00
|
|
|
if (multiviewLayout == MultiviewLayout::HORIZONTAL_TOP_24_SCENES) {
|
|
|
|
// Just paint the background for now
|
|
|
|
paintAreaWithColor(window->thickness, window->thickness,
|
2019-06-22 22:13:45 -07: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-03-22 20:57:15 -07:00
|
|
|
}
|
|
|
|
|
2018-03-08 15:27:15 -08:00
|
|
|
endRegion();
|
2015-04-04 00:37:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void OBSProjector::OBSRender(void *data, uint32_t cx, uint32_t cy)
|
|
|
|
{
|
2019-06-22 22:13:45 -07:00
|
|
|
OBSProjector *window = reinterpret_cast<OBSProjector *>(data);
|
2017-10-21 10:51:01 -07:00
|
|
|
|
|
|
|
if (!window->ready)
|
|
|
|
return;
|
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
OBSBasic *main = reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
|
2018-02-27 21:31:35 -08:00
|
|
|
OBSSource source = window->source;
|
2015-04-04 00:37:02 -07:00
|
|
|
|
|
|
|
uint32_t targetCX;
|
|
|
|
uint32_t targetCY;
|
2019-06-22 22:13:45 -07:00
|
|
|
int x, y;
|
|
|
|
int newCX, newCY;
|
|
|
|
float scale;
|
2015-04-04 00:37:02 -07:00
|
|
|
|
2018-02-27 21:31:35 -08:00
|
|
|
if (source) {
|
|
|
|
targetCX = std::max(obs_source_get_width(source), 1u);
|
|
|
|
targetCY = std::max(obs_source_get_height(source), 1u);
|
2015-04-04 00:37:02 -07: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-03-08 15:27:15 -08:00
|
|
|
startRegion(x, y, newCX, newCY, 0.0f, float(targetCX), 0.0f,
|
2019-06-22 22:13:45 -07:00
|
|
|
float(targetCY));
|
2015-04-04 00:37:02 -07:00
|
|
|
|
2017-10-21 10:51:01 -07:00
|
|
|
if (window->type == ProjectorType::Preview &&
|
|
|
|
main->IsPreviewProgramMode()) {
|
2017-11-08 19:38:44 -08:00
|
|
|
OBSSource curSource = main->GetCurrentSceneSource();
|
|
|
|
|
2018-02-27 21:31:35 -08:00
|
|
|
if (source != curSource) {
|
|
|
|
obs_source_dec_showing(source);
|
2017-11-08 19:38:44 -08:00
|
|
|
obs_source_inc_showing(curSource);
|
2017-11-30 11:39:18 -08:00
|
|
|
source = curSource;
|
2019-01-13 21:00:46 -08:00
|
|
|
window->source = source;
|
2017-11-08 19:38:44 -08:00
|
|
|
}
|
2019-10-09 00:43:48 -07:00
|
|
|
} else if (window->type == ProjectorType::Preview &&
|
|
|
|
!main->IsPreviewProgramMode()) {
|
|
|
|
window->source = nullptr;
|
2017-11-08 19:38:44 -08:00
|
|
|
}
|
|
|
|
|
2018-03-08 15:27:15 -08:00
|
|
|
if (source)
|
2017-11-30 11:39:18 -08:00
|
|
|
obs_source_video_render(source);
|
2018-03-08 15:27:15 -08:00
|
|
|
else
|
2018-01-01 18:33:44 -08:00
|
|
|
obs_render_main_texture();
|
2015-04-04 00:37:02 -07:00
|
|
|
|
2018-03-08 15:27:15 -08:00
|
|
|
endRegion();
|
2015-04-04 00:37:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void OBSProjector::OBSSourceRemoved(void *data, calldata_t *params)
|
|
|
|
{
|
2019-06-22 22:13:45 -07:00
|
|
|
OBSProjector *window = reinterpret_cast<OBSProjector *>(data);
|
2016-12-29 07:21:53 -08:00
|
|
|
|
2015-04-04 00:37:02 -07:00
|
|
|
window->deleteLater();
|
|
|
|
|
|
|
|
UNUSED_PARAMETER(params);
|
|
|
|
}
|
|
|
|
|
2018-03-22 18:07:59 -07:00
|
|
|
static int getSourceByPosition(int x, int y, float ratio)
|
2017-12-12 12:45:15 -08:00
|
|
|
{
|
2018-08-28 20:51:45 -07:00
|
|
|
int pos = -1;
|
|
|
|
QWidget *rec = QApplication::activeWindow();
|
|
|
|
if (!rec)
|
|
|
|
return pos;
|
2019-06-22 22:13:45 -07:00
|
|
|
int cx = rec->width();
|
|
|
|
int cy = rec->height();
|
|
|
|
int minX = 0;
|
|
|
|
int minY = 0;
|
|
|
|
int maxX = cx;
|
|
|
|
int maxY = cy;
|
2017-12-12 12:45:15 -08:00
|
|
|
|
2017-12-13 13:42:19 -08:00
|
|
|
switch (multiviewLayout) {
|
2018-03-22 20:57:15 -07: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;
|
2018-03-20 17:41:39 -07:00
|
|
|
case MultiviewLayout::VERTICAL_LEFT_8_SCENES:
|
2017-12-13 13:42:19 -08:00
|
|
|
if (float(cx) / float(cy) > ratio) {
|
|
|
|
int validX = cy * ratio;
|
2018-03-22 20:57:15 -07:00
|
|
|
maxX = (cx / 2) + (validX / 2);
|
2017-12-13 13:42:19 -08:00
|
|
|
} else {
|
|
|
|
int validY = cx / ratio;
|
2018-03-22 20:57:15 -07:00
|
|
|
minY = (cy / 2) - (validY / 2);
|
|
|
|
maxY = (cy / 2) + (validY / 2);
|
2017-12-13 13:42:19 -08:00
|
|
|
}
|
|
|
|
|
2018-03-22 20:57:15 -07:00
|
|
|
minX = cx / 2;
|
2017-12-13 13:42:19 -08: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-03-20 17:41:39 -07:00
|
|
|
case MultiviewLayout::VERTICAL_RIGHT_8_SCENES:
|
2017-12-13 13:42:19 -08:00
|
|
|
if (float(cx) / float(cy) > ratio) {
|
|
|
|
int validX = cy * ratio;
|
2018-03-22 20:57:15 -07:00
|
|
|
minX = (cx / 2) - (validX / 2);
|
2017-12-13 13:42:19 -08:00
|
|
|
} else {
|
|
|
|
int validY = cx / ratio;
|
2018-03-22 20:57:15 -07:00
|
|
|
minY = (cy / 2) - (validY / 2);
|
|
|
|
maxY = (cy / 2) + (validY / 2);
|
2017-12-13 13:42:19 -08:00
|
|
|
}
|
|
|
|
|
2018-03-22 20:57:15 -07:00
|
|
|
maxX = (cx / 2);
|
2017-12-12 12:45:15 -08:00
|
|
|
|
2017-12-13 13:42:19 -08:00
|
|
|
if (x < minX || x > maxX || y < minY || y > maxY)
|
|
|
|
break;
|
2017-12-12 12:45:15 -08:00
|
|
|
|
2017-12-13 13:42:19 -08:00
|
|
|
pos = 2 * ((y - minY) / ((maxY - minY) / 4));
|
|
|
|
if (x > minX + ((maxX - minX) / 2))
|
|
|
|
pos++;
|
|
|
|
break;
|
2018-03-20 17:41:39 -07:00
|
|
|
case MultiviewLayout::HORIZONTAL_BOTTOM_8_SCENES:
|
2017-12-13 13:42:19 -08:00
|
|
|
if (float(cx) / float(cy) > ratio) {
|
|
|
|
int validX = cy * ratio;
|
2018-03-22 20:57:15 -07:00
|
|
|
minX = (cx / 2) - (validX / 2);
|
|
|
|
maxX = (cx / 2) + (validX / 2);
|
2017-12-13 13:42:19 -08:00
|
|
|
} else {
|
|
|
|
int validY = cx / ratio;
|
2018-03-22 20:57:15 -07:00
|
|
|
minY = (cy / 2) - (validY / 2);
|
2017-12-13 13:42:19 -08:00
|
|
|
}
|
|
|
|
|
2018-03-22 20:57:15 -07:00
|
|
|
maxY = (cy / 2);
|
2017-12-12 12:45:15 -08:00
|
|
|
|
2017-12-13 13:42:19 -08: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-03-20 17:41:39 -07:00
|
|
|
default: // MultiviewLayout::HORIZONTAL_TOP_8_SCENES
|
2017-12-13 13:42:19 -08:00
|
|
|
if (float(cx) / float(cy) > ratio) {
|
|
|
|
int validX = cy * ratio;
|
2018-03-22 20:57:15 -07:00
|
|
|
minX = (cx / 2) - (validX / 2);
|
|
|
|
maxX = (cx / 2) + (validX / 2);
|
2017-12-13 13:42:19 -08:00
|
|
|
} else {
|
|
|
|
int validY = cx / ratio;
|
2018-03-22 20:57:15 -07:00
|
|
|
maxY = (cy / 2) + (validY / 2);
|
2017-12-13 13:42:19 -08:00
|
|
|
}
|
|
|
|
|
2018-03-22 20:57:15 -07:00
|
|
|
minY = (cy / 2);
|
2017-12-13 13:42:19 -08: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;
|
|
|
|
}
|
2017-12-12 12:45:15 -08:00
|
|
|
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OBSProjector::mouseDoubleClickEvent(QMouseEvent *event)
|
|
|
|
{
|
|
|
|
OBSQTDisplay::mouseDoubleClickEvent(event);
|
|
|
|
|
2018-03-19 19:27:44 -07:00
|
|
|
if (!mouseSwitching)
|
2018-03-16 14:55:56 -07:00
|
|
|
return;
|
|
|
|
|
2018-03-19 19:27:44 -07:00
|
|
|
if (!transitionOnDoubleClick)
|
2017-12-12 12:45:15 -08:00
|
|
|
return;
|
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
OBSBasic *main = (OBSBasic *)obs_frontend_get_main_window();
|
2017-12-12 12:45:15 -08:00
|
|
|
if (!main->IsPreviewProgramMode())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (event->button() == Qt::LeftButton) {
|
2018-03-22 18:07:59 -07:00
|
|
|
int pos = getSourceByPosition(event->x(), event->y(), ratio);
|
2018-03-22 20:57:15 -07:00
|
|
|
if (pos < 0 || pos >= (int)numSrcs)
|
2017-12-12 12:45:15 -08:00
|
|
|
return;
|
|
|
|
OBSSource src = OBSGetStrongRef(multiviewScenes[pos]);
|
|
|
|
if (!src)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (main->GetProgramSource() != src)
|
|
|
|
main->TransitionToScene(src);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-13 14:31:36 -07:00
|
|
|
void OBSProjector::mousePressEvent(QMouseEvent *event)
|
|
|
|
{
|
|
|
|
OBSQTDisplay::mousePressEvent(event);
|
|
|
|
|
|
|
|
if (event->button() == Qt::RightButton) {
|
2019-10-07 22:43:10 -07:00
|
|
|
OBSBasic *main =
|
|
|
|
reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
|
2015-04-13 14:31:36 -07:00
|
|
|
QMenu popup(this);
|
2019-10-07 22:43:10 -07:00
|
|
|
|
|
|
|
QMenu *projectorMenu = new QMenu(QTStr("Fullscreen"));
|
|
|
|
main->AddProjectorMenuMonitors(projectorMenu, this,
|
|
|
|
SLOT(OpenFullScreenProjector()));
|
|
|
|
popup.addMenu(projectorMenu);
|
|
|
|
|
|
|
|
if (GetMonitor() > -1)
|
|
|
|
popup.addAction(QTStr("Windowed"), this,
|
|
|
|
SLOT(OpenWindowedProjector()));
|
|
|
|
|
2015-04-13 14:31:36 -07:00
|
|
|
popup.addAction(QTStr("Close"), this, SLOT(EscapeTriggered()));
|
|
|
|
popup.exec(QCursor::pos());
|
|
|
|
}
|
2017-12-12 12:45:15 -08:00
|
|
|
|
2018-03-19 19:27:44 -07:00
|
|
|
if (!mouseSwitching)
|
|
|
|
return;
|
2018-03-16 14:55:56 -07:00
|
|
|
|
2018-03-19 19:27:44 -07:00
|
|
|
if (event->button() == Qt::LeftButton) {
|
2018-03-22 18:07:59 -07:00
|
|
|
int pos = getSourceByPosition(event->x(), event->y(), ratio);
|
2018-03-22 20:57:15 -07:00
|
|
|
if (pos < 0 || pos >= (int)numSrcs)
|
2017-12-12 12:45:15 -08:00
|
|
|
return;
|
|
|
|
OBSSource src = OBSGetStrongRef(multiviewScenes[pos]);
|
|
|
|
if (!src)
|
|
|
|
return;
|
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
OBSBasic *main = (OBSBasic *)obs_frontend_get_main_window();
|
2017-12-12 12:45:15 -08:00
|
|
|
if (main->GetCurrentSceneSource() != src)
|
|
|
|
main->SetCurrentScene(src, false);
|
|
|
|
}
|
2015-04-13 14:31:36 -07:00
|
|
|
}
|
|
|
|
|
2015-04-04 00:37:02 -07:00
|
|
|
void OBSProjector::EscapeTriggered()
|
|
|
|
{
|
2019-10-07 22:43:10 -07:00
|
|
|
OBSBasic *main = reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
|
|
|
|
main->DeleteProjector(this);
|
2015-04-04 00:37:02 -07:00
|
|
|
}
|
2017-10-21 10:51:01 -07:00
|
|
|
|
|
|
|
void OBSProjector::UpdateMultiview()
|
|
|
|
{
|
2018-03-22 20:57:15 -07:00
|
|
|
multiviewScenes.clear();
|
|
|
|
multiviewLabels.clear();
|
2017-10-21 10:51:01 -07:00
|
|
|
|
|
|
|
struct obs_video_info ovi;
|
|
|
|
obs_get_video_info(&ovi);
|
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
uint32_t w = ovi.base_width;
|
|
|
|
uint32_t h = ovi.base_height;
|
|
|
|
fw = float(w);
|
|
|
|
fh = float(h);
|
|
|
|
ratio = fw / fh;
|
2017-10-21 10:51:01 -07:00
|
|
|
|
|
|
|
struct obs_frontend_source_list scenes = {};
|
|
|
|
obs_frontend_get_scenes(&scenes);
|
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
multiviewLabels.emplace_back(
|
|
|
|
CreateLabel(Str("StudioMode.Preview"), h / 2));
|
|
|
|
multiviewLabels.emplace_back(
|
|
|
|
CreateLabel(Str("StudioMode.Program"), h / 2));
|
2017-10-21 10:51:01 -07:00
|
|
|
|
2018-03-20 20:16:42 -07:00
|
|
|
multiviewLayout = static_cast<MultiviewLayout>(config_get_int(
|
2019-06-22 22:13:45 -07:00
|
|
|
GetGlobalConfig(), "BasicWindow", "MultiviewLayout"));
|
2018-03-20 20:16:42 -07:00
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
drawLabel = config_get_bool(GetGlobalConfig(), "BasicWindow",
|
|
|
|
"MultiviewDrawNames");
|
2018-03-20 20:16:42 -07:00
|
|
|
|
|
|
|
drawSafeArea = config_get_bool(GetGlobalConfig(), "BasicWindow",
|
2019-06-22 22:13:45 -07:00
|
|
|
"MultiviewDrawAreas");
|
2018-03-20 20:16:42 -07:00
|
|
|
|
|
|
|
mouseSwitching = config_get_bool(GetGlobalConfig(), "BasicWindow",
|
2019-06-22 22:13:45 -07:00
|
|
|
"MultiviewMouseSwitch");
|
2018-03-20 20:16:42 -07:00
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
transitionOnDoubleClick = config_get_bool(
|
|
|
|
GetGlobalConfig(), "BasicWindow", "TransitionOnDoubleClick");
|
2018-03-20 20:16:42 -07:00
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
switch (multiviewLayout) {
|
2018-03-22 20:57:15 -07:00
|
|
|
case MultiviewLayout::HORIZONTAL_TOP_24_SCENES:
|
2019-06-22 22:13:45 -07:00
|
|
|
pvwprgCX = fw / 3;
|
|
|
|
pvwprgCY = fh / 3;
|
2018-03-22 20:57:15 -07:00
|
|
|
|
|
|
|
maxSrcs = 24;
|
|
|
|
break;
|
|
|
|
default:
|
2019-06-22 22:13:45 -07:00
|
|
|
pvwprgCX = fw / 2;
|
|
|
|
pvwprgCY = fh / 2;
|
2018-03-22 20:57:15 -07:00
|
|
|
|
|
|
|
maxSrcs = 8;
|
2018-03-20 20:16:42 -07:00
|
|
|
}
|
|
|
|
|
2019-06-22 22:13:45 -07:00
|
|
|
ppiCX = pvwprgCX - thicknessx2;
|
|
|
|
ppiCY = pvwprgCY - thicknessx2;
|
2018-03-22 20:57:15 -07:00
|
|
|
ppiScaleX = (pvwprgCX - thicknessx2) / fw;
|
|
|
|
ppiScaleY = (pvwprgCY - thicknessx2) / fh;
|
|
|
|
|
|
|
|
scenesCX = pvwprgCX / 2;
|
|
|
|
scenesCY = pvwprgCY / 2;
|
2019-06-22 22:13:45 -07:00
|
|
|
siCX = scenesCX - thicknessx2;
|
|
|
|
siCY = scenesCY - thicknessx2;
|
|
|
|
siScaleX = (scenesCX - thicknessx2) / fw;
|
|
|
|
siScaleY = (scenesCY - thicknessx2) / fh;
|
2018-03-22 20:57:15 -07:00
|
|
|
|
|
|
|
numSrcs = 0;
|
2018-08-16 07:52:43 -07:00
|
|
|
size_t i = 0;
|
|
|
|
while (i < scenes.sources.num && numSrcs < maxSrcs) {
|
|
|
|
obs_source_t *src = scenes.sources.array[i++];
|
2017-10-21 10:51:01 -07: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-03-22 20:57:15 -07:00
|
|
|
// We have a displayable source.
|
|
|
|
numSrcs++;
|
2017-10-21 10:51:01 -07:00
|
|
|
|
2018-03-22 20:57:15 -07:00
|
|
|
multiviewScenes.emplace_back(OBSGetWeakRef(src));
|
|
|
|
obs_source_inc_showing(src);
|
2017-10-21 10:51:01 -07:00
|
|
|
|
2018-03-22 20:57:15 -07:00
|
|
|
std::string name = std::to_string(numSrcs) + " - " +
|
2019-06-22 22:13:45 -07:00
|
|
|
obs_source_get_name(src);
|
2018-03-22 20:57:15 -07:00
|
|
|
multiviewLabels.emplace_back(CreateLabel(name.c_str(), h / 3));
|
2017-10-21 10:51:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
obs_frontend_source_list_free(&scenes);
|
|
|
|
}
|
|
|
|
|
2018-02-28 16:43:07 -08:00
|
|
|
void OBSProjector::UpdateProjectorTitle(QString name)
|
|
|
|
{
|
2019-10-07 22:43:10 -07:00
|
|
|
bool window = (GetMonitor() == -1);
|
2018-02-28 16:43:07 -08:00
|
|
|
|
|
|
|
QString title = nullptr;
|
|
|
|
switch (type) {
|
|
|
|
case ProjectorType::Scene:
|
2019-10-07 22:43:10 -07:00
|
|
|
if (!window)
|
|
|
|
title = QTStr("SceneProjector") + " - " + name;
|
|
|
|
else
|
|
|
|
title = QTStr("SceneWindow") + " - " + name;
|
2018-02-28 16:43:07 -08:00
|
|
|
break;
|
|
|
|
case ProjectorType::Source:
|
2019-10-07 22:43:10 -07: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
|
2020-03-08 20:20:38 -07:00
|
|
|
title = QTStr("MultiviewWindowed");
|
2018-02-28 16:43:07 -08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
title = name;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
setWindowTitle(title);
|
|
|
|
}
|
|
|
|
|
2018-02-28 10:34:17 -08:00
|
|
|
OBSSource OBSProjector::GetSource()
|
|
|
|
{
|
|
|
|
return source;
|
|
|
|
}
|
|
|
|
|
|
|
|
ProjectorType OBSProjector::GetProjectorType()
|
|
|
|
{
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
int OBSProjector::GetMonitor()
|
|
|
|
{
|
|
|
|
return savedMonitor;
|
|
|
|
}
|
|
|
|
|
2017-10-21 10:51:01 -07: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-02-28 16:43:07 -08:00
|
|
|
|
|
|
|
void OBSProjector::RenameProjector(QString oldName, QString newName)
|
|
|
|
{
|
2019-10-07 22:43:10 -07:00
|
|
|
if (oldName == newName)
|
|
|
|
return;
|
|
|
|
|
|
|
|
UpdateProjectorTitle(newName);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OBSProjector::OpenFullScreenProjector()
|
|
|
|
{
|
|
|
|
if (!isFullScreen())
|
|
|
|
prevGeometry = geometry();
|
|
|
|
|
|
|
|
int monitor = sender()->property("monitor").toInt();
|
|
|
|
SetMonitor(monitor);
|
|
|
|
SetHideCursor();
|
|
|
|
|
|
|
|
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)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void OBSProjector::closeEvent(QCloseEvent *event)
|
|
|
|
{
|
|
|
|
EscapeTriggered();
|
|
|
|
event->accept();
|
2018-02-28 16:43:07 -08:00
|
|
|
}
|