ask the user whether to stop a rendering process when accidentally dragging the mouse in an ongoing rendering session
parent
d432f51ae6
commit
31fc89690d
|
@ -98,6 +98,15 @@ public:
|
|||
/// Get a pointer to the underlying scene (const version)
|
||||
inline const Scene *getScene() const { return m_scene.get(); }
|
||||
|
||||
/// Get a pointer to the underlying render queue
|
||||
inline RenderQueue *getRenderQueue() { return m_queue.get(); }
|
||||
|
||||
/// Get a pointer to the underlying render queue (const version)
|
||||
inline const RenderQueue *getRenderQueue() const { return m_queue.get(); }
|
||||
|
||||
/// Return the amount of time spent rendering the given job (in seconds)
|
||||
inline Float getRenderTime() const { return m_queue->getRenderTime(this); }
|
||||
|
||||
MTS_DECLARE_CLASS()
|
||||
protected:
|
||||
/// Virtual destructor
|
||||
|
|
|
@ -362,12 +362,14 @@ void export_render() {
|
|||
.staticmethod("loadScene");
|
||||
|
||||
Scene *(RenderJob::*renderJob_getScene)(void) = &RenderJob::getScene;
|
||||
RenderQueue *(RenderJob::*renderJob_getRenderQueue)(void) = &RenderJob::getRenderQueue;
|
||||
BP_CLASS(RenderJob, Thread, (bp::init<const std::string &, Scene *, RenderQueue *>()))
|
||||
.def(bp::init<const std::string &, Scene *, RenderQueue *, int, bp::optional<int, int> >())
|
||||
.def("flush", &RenderJob::flush)
|
||||
.def("cancel", renderJob_cancel)
|
||||
.def("wait", &RenderJob::wait)
|
||||
.def("getScene", renderJob_getScene, BP_RETURN_VALUE);
|
||||
.def("getScene", renderJob_getScene, BP_RETURN_VALUE)
|
||||
.def("getRenderQueue", renderJob_getRenderQueue, BP_RETURN_VALUE);
|
||||
|
||||
BP_CLASS(RenderQueue, Object, bp::init<>())
|
||||
.def("getJobCount", &RenderQueue::getJobCount)
|
||||
|
|
|
@ -386,13 +386,11 @@ void GLWidget::focusOutEvent(QFocusEvent *event) {
|
|||
m_movementTimer->stop();
|
||||
}
|
||||
|
||||
|
||||
void GLWidget::timerImpulse() {
|
||||
if (!m_context || !m_context->scene || !m_preview->isRunning()) {
|
||||
m_movementTimer->stop();
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_animation) {
|
||||
Float x = std::min(m_animationTimer->getMilliseconds() / 500.0f, 1.0f);
|
||||
Float t = x*x*x*(x*(x*6-15)+10); // smootherstep by Ken Perlin
|
||||
|
@ -453,6 +451,23 @@ void GLWidget::timerImpulse() {
|
|||
resetPreview();
|
||||
}
|
||||
|
||||
bool GLWidget::askReallyCancelRendering() {
|
||||
try {
|
||||
Float renderTime = m_context->renderJob->getRenderTime();
|
||||
|
||||
if (renderTime < 10) /* Only ask for jobs that have been rendering for a bit */
|
||||
return true;
|
||||
} catch (...) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool cancel = QMessageBox::question(this,
|
||||
"Really cancel rendering?", "Camera motion detected. Do you really want to cancel the rendering?",
|
||||
QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes;
|
||||
|
||||
return cancel;
|
||||
}
|
||||
|
||||
void GLWidget::resetPreview() {
|
||||
if (!m_context || !m_context->scene || !m_preview->isRunning())
|
||||
return;
|
||||
|
@ -543,6 +558,12 @@ void GLWidget::keyPressEvent(QKeyEvent *event) {
|
|||
}
|
||||
if (!m_movementTimer->isActive() && (m_leftKeyDown || m_rightKeyDown
|
||||
|| m_upKeyDown || m_downKeyDown)) {
|
||||
|
||||
if (m_context->renderJob && !askReallyCancelRendering()) {
|
||||
m_leftKeyDown = m_rightKeyDown = m_upKeyDown = m_downKeyDown = false;
|
||||
return;
|
||||
}
|
||||
|
||||
m_clock->reset();
|
||||
m_movementTimer->start();
|
||||
}
|
||||
|
@ -615,6 +636,12 @@ void GLWidget::mouseMoveEvent(QMouseEvent *event) {
|
|||
nearClip = camera->getNearClip(),
|
||||
farClip = camera->getFarClip();
|
||||
|
||||
bool setCursor = true;
|
||||
if (m_context->renderJob) {
|
||||
if (!askReallyCancelRendering())
|
||||
return;
|
||||
setCursor = false;
|
||||
}
|
||||
if (focusDistance <= nearClip || focusDistance >= farClip) {
|
||||
focusDistance = autoFocus();
|
||||
camera->setFocusDistance(focusDistance);
|
||||
|
@ -623,7 +650,7 @@ void GLWidget::mouseMoveEvent(QMouseEvent *event) {
|
|||
Point target = p + d * focusDistance;
|
||||
Vector up = m_context->up;
|
||||
|
||||
if (!m_didSetCursor) {
|
||||
if (!m_didSetCursor && setCursor) {
|
||||
QApplication::setOverrideCursor(Qt::BlankCursor);
|
||||
m_didSetCursor = true;
|
||||
}
|
||||
|
@ -828,11 +855,13 @@ void GLWidget::wheelEvent(QWheelEvent *event) {
|
|||
} else {
|
||||
if (!m_preview->isRunning() || m_context == NULL || m_context->scene == NULL || m_animation)
|
||||
return;
|
||||
|
||||
PerspectiveCamera *camera = getPerspectiveCamera();
|
||||
if (!camera)
|
||||
return;
|
||||
|
||||
if (m_context->renderJob && !askReallyCancelRendering())
|
||||
return;
|
||||
|
||||
Float focusDistance = camera->getFocusDistance(),
|
||||
nearClip = camera->getNearClip(),
|
||||
farClip = camera->getFarClip();
|
||||
|
|
|
@ -127,6 +127,7 @@ protected:
|
|||
Point2i upperLeft(bool flipY = false) const;
|
||||
void reveal(const AABB &aabb);
|
||||
Float autoFocus() const;
|
||||
bool askReallyCancelRendering();
|
||||
|
||||
inline ProjectiveCamera *getProjectiveCamera() {
|
||||
Sensor *sensor = m_context->scene->getSensor();
|
||||
|
|
Loading…
Reference in New Issue