Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Screenshot area #1263

Merged
merged 2 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions plugins/video/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ target_sources(
macro-condition-video.hpp
opencv-helpers.cpp
opencv-helpers.hpp
paramerter-wrappers.cpp
paramerter-wrappers.hpp
parameter-wrappers.cpp
parameter-wrappers.hpp
preview-dialog.cpp
preview-dialog.hpp
screenshot-dialog.cpp
Expand Down
4 changes: 2 additions & 2 deletions plugins/video/macro-condition-video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1433,8 +1433,8 @@ void MacroConditionVideoEdit::ImageBrowseButtonClicked()
return;
}

auto screenshot =
ScreenshotDialog::AskForScreenshot(_entryData->_video);
auto screenshot = ScreenshotDialog::AskForScreenshot(
_entryData->_video, _entryData->_areaParameters);
if (!screenshot) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/video/macro-condition-video.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
#include "opencv-helpers.hpp"
#include "area-selection.hpp"
#include "paramerter-wrappers.hpp"
#include "parameter-wrappers.hpp"
#include "preview-dialog.hpp"

#include <macro-condition-edit.hpp>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "paramerter-wrappers.hpp"
#include "parameter-wrappers.hpp"

#include <QFileInfo>
#include <source-helpers.hpp>
Expand Down
2 changes: 1 addition & 1 deletion plugins/video/preview-dialog.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include "paramerter-wrappers.hpp"
#include "parameter-wrappers.hpp"

#include <QDialog>
#include <QLabel>
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
9 changes: 5 additions & 4 deletions plugins/video/screenshot-dialog.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include "screenshot-helper.hpp"
#include "paramerter-wrappers.hpp"
#include "parameter-wrappers.hpp"

#include <optional>
#include <obs.h>
Expand All @@ -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
Loading