Use only one widget for preview

Modify the obs_display API so that it always uses an orthographic
projection that is the size of the display, rather than OBS' base size.
Having it do an orthographic projection to OBS' base size was silly
because it meant that everything would be skewed if you wanted to draw
1:1 in the display.  This deoes mean that the callbacks must handle
resizing the images, but it's worth it to ensure 1:1 draw sizes.

As for the preview widget, instead of making some funky widget within
widget that resizes, it's just going to be a widget within the entire
top layout.  Also changed the preview padding color to gray.
This commit is contained in:
jp9000
2014-03-07 10:19:03 -07:00
parent 7d48dbb1dc
commit e8044d0868
7 changed files with 45 additions and 47 deletions
+27 -12
View File
@@ -133,9 +133,6 @@ void OBSBasic::OBSInit()
obs_load_module("win-wasapi");
obs_load_module("win-capture");
#endif
/* HACK: fixes a qt bug with native widgets with native repaint */
ui->previewContainer->repaint();
}
OBSBasic::~OBSBasic()
@@ -341,9 +338,13 @@ void OBSBasic::ChannelChanged(void *data, calldata_t params)
void OBSBasic::RenderMain(void *data, uint32_t cx, uint32_t cy)
{
OBSBasic *window = static_cast<OBSBasic*>(data);
gs_matrix_push();
gs_matrix_scale3f(window->previewScale, window->previewScale, 1.0f);
gs_matrix_translate3f(-window->previewX, -window->previewY, 0.0f);
obs_render_main_view();
gs_matrix_pop();
UNUSED_PARAMETER(data);
UNUSED_PARAMETER(cx);
UNUSED_PARAMETER(cy);
}
@@ -369,7 +370,7 @@ bool OBSBasic::ResetVideo()
ovi.adapter = 0;
ovi.gpu_conversion = true;
QTToGSWindow(ui->preview, ovi.window);
QTToGSWindow(ui->preview->winId(), ovi.window);
//required to make opengl display stuff on osx(?)
ResizePreview(ovi.base_width, ovi.base_height);
@@ -414,25 +415,28 @@ void OBSBasic::ResizePreview(uint32_t cx, uint32_t cy)
int x, y;
/* resize preview panel to fix to the top section of the window */
targetSize = ui->previewContainer->size();
targetSize = ui->preview->size();
targetAspect = double(targetSize.width()) / double(targetSize.height());
baseAspect = double(cx) / double(cy);
if (targetAspect > baseAspect) {
previewScale = float(targetSize.height()) / float(cy);
cx = targetSize.height() * baseAspect;
cy = targetSize.height();
} else {
previewScale = float(targetSize.width()) / float(cx);
cx = targetSize.width();
cy = targetSize.width() / baseAspect;
}
x = targetSize.width() /2 - cx/2;
y = targetSize.height()/2 - cy/2;
previewX = targetSize.width() /2 - cx/2;
previewY = targetSize.height()/2 - cy/2;
ui->preview->setGeometry(x, y, cx, cy);
if (isVisible())
obs_resize(cx, cy);
if (isVisible()) {
if (resizeTimer)
killTimer(resizeTimer);
resizeTimer = startTimer(100);
}
}
void OBSBasic::closeEvent(QCloseEvent *event)
@@ -457,6 +461,17 @@ void OBSBasic::resizeEvent(QResizeEvent *event)
UNUSED_PARAMETER(event);
}
void OBSBasic::timerEvent(QTimerEvent *event)
{
if (event->timerId() == resizeTimer) {
killTimer(resizeTimer);
resizeTimer = 0;
QSize size = ui->preview->size();
obs_resize(size.width(), size.height());
}
}
void OBSBasic::on_action_New_triggered()
{
/* TODO */