Skip to content

Commit

Permalink
Reduce screenshot selection area to area to be checked
Browse files Browse the repository at this point in the history
  • Loading branch information
WarmUpTill committed Nov 16, 2024
1 parent 5a8627c commit 5614b72
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
5 changes: 3 additions & 2 deletions plugins/video/macro-condition-video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1433,8 +1433,9 @@ void MacroConditionVideoEdit::ImageBrowseButtonClicked()
return;
}

auto screenshot =
ScreenshotDialog::AskForScreenshot(_entryData->_video);
;
auto screenshot = ScreenshotDialog::AskForScreenshot(
_entryData->_video, _entryData->_areaParameters);
if (!screenshot) {
return;
}
Expand Down
22 changes: 14 additions & 8 deletions plugins/video/screenshot-dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,27 @@

namespace advss {

ScreenshotDialog::ScreenshotDialog(obs_source_t *source)
ScreenshotDialog::ScreenshotDialog(obs_source_t *source,
const AreaParameters &area)
: QDialog(GetSettingsWindow()),
_scrollArea(new QScrollArea),
_imageLabel(new QLabel(this)),
_rubberBand(new QRubberBand(QRubberBand::Rectangle, this)),
_buttonbox(new QDialogButtonBox(QDialogButtonBox::Ok |
_buttonBox(new QDialogButtonBox(QDialogButtonBox::Ok |
QDialogButtonBox::Cancel)),
_screenshot(source, {}, true)
_screenshot(source,
area.enable ? QRect(area.area.x, area.area.y,
area.area.width, area.area.height)
: QRect(),
true)
{
setWindowTitle(obs_module_text("AdvSceneSwitcher.windowTitle"));
setWindowFlags(windowFlags() | Qt::WindowMaximizeButtonHint |
Qt::WindowCloseButtonHint);

QWidget::connect(_buttonbox, &QDialogButtonBox::accepted, this,
QWidget::connect(_buttonBox, &QDialogButtonBox::accepted, this,
&QDialog::accept);
QWidget::connect(_buttonbox, &QDialogButtonBox::rejected, this,
QWidget::connect(_buttonBox, &QDialogButtonBox::rejected, this,
&QDialog::reject);

_imageLabel->setPixmap(QPixmap::fromImage(_screenshot.GetImage()));
Expand All @@ -48,7 +53,7 @@ ScreenshotDialog::ScreenshotDialog(obs_source_t *source)
layout->addWidget(new QLabel(obs_module_text(
"AdvSceneSwitcher.condition.video.screenshot.selectArea")));
layout->addWidget(_scrollArea);
layout->addWidget(_buttonbox);
layout->addWidget(_buttonBox);
setLayout(layout);

_result = _screenshot.GetImage();
Expand Down Expand Up @@ -95,14 +100,15 @@ void ScreenshotDialog::mouseReleaseEvent(QMouseEvent *)
}

std::optional<QImage>
ScreenshotDialog::AskForScreenshot(const VideoInput &input)
ScreenshotDialog::AskForScreenshot(const VideoInput &input,
const AreaParameters &area)
{
if (!input.ValidSelection()) {
return {};
}

auto source = OBSGetStrongRef(input.GetVideo());
ScreenshotDialog dialog(source);
ScreenshotDialog dialog(source, area);
if (dialog.exec() != DialogCode::Accepted) {
return {};
}
Expand Down
7 changes: 4 additions & 3 deletions plugins/video/screenshot-dialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ class ScreenshotDialog : public QDialog {
Q_OBJECT

public:
static std::optional<QImage> AskForScreenshot(const VideoInput &);
static std::optional<QImage> AskForScreenshot(const VideoInput &,
const AreaParameters &);

private:
ScreenshotDialog(obs_source_t *source);
ScreenshotDialog(obs_source_t *source, const AreaParameters &area);

void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
Expand All @@ -32,7 +33,7 @@ class ScreenshotDialog : public QDialog {
QPoint _origin;
QRubberBand *_rubberBand = nullptr;

QDialogButtonBox *_buttonbox;
QDialogButtonBox *_buttonBox;

QImage _result;
Screenshot _screenshot;
Expand Down

0 comments on commit 5614b72

Please sign in to comment.