Skip to content

Commit

Permalink
fix UX bugs with new viewport
Browse files Browse the repository at this point in the history
  • Loading branch information
fu5ha committed Jul 10, 2019
1 parent 04f893e commit 797d142
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#include "mainwindow/rendering/lightpathspickinghandler.h"
#include "mainwindow/rendering/lightpathslayer.h"
#include "mainwindow/rendering/viewporttab.h"
#include "mainwindow/rendering/viewportwidget.h"
#include "utility/miscellaneous.h"
#include "utility/settingskeys.h"

Expand Down Expand Up @@ -77,9 +76,11 @@ namespace studio {

LightPathsViewportManager::LightPathsViewportManager(
ViewportTab* viewport_tab,
Project& project,
Project* project,
ParamArray& settings)
: m_enabled(false)
, m_picking_enabled(true)
, m_paths_display_active(false)
, m_project(project)
, m_settings(settings)
, m_viewport_tab(viewport_tab)
Expand All @@ -94,15 +95,49 @@ LightPathsViewportManager::LightPathsViewportManager(
recreate_handlers();
}

void LightPathsViewportManager::reset(renderer::Project* project)
{
set_enabled(false);
set_display_enabled(false);
set_picking_enabled(true);
m_project = project;
}

void LightPathsViewportManager::slot_base_layer_changed(const ViewportWidget::BaseLayer layer)
{
if (layer == ViewportWidget::BaseLayer::FinalRender)
set_picking_enabled(true);
else
set_picking_enabled(false);
}

void LightPathsViewportManager::set_enabled(const bool enabled)
{
m_enabled = enabled;
if (enabled)
{
m_toolbar->show();
}
else
{
set_display_enabled(false);
m_toolbar->hide();

}
m_toolbar->setDisabled(!enabled);

emit signal_should_display(m_enabled && m_paths_display_active);
}

void LightPathsViewportManager::set_display_enabled(const bool enabled)
{
m_paths_display_active = enabled;

emit signal_should_display(m_enabled && m_paths_display_active);
}

void LightPathsViewportManager::set_picking_enabled(const bool enabled)
{
m_picking_enabled = enabled;
m_screen_space_paths_picking_handler->set_enabled(enabled);
}

Expand All @@ -113,9 +148,11 @@ QToolBar* LightPathsViewportManager::toolbar() const

void LightPathsViewportManager::slot_entity_picked(const ScenePicker::PickingResult& result)
{
if (!m_enabled) return;
if (!m_picking_enabled || !m_enabled) return;

const CanvasProperties& props = m_project.get_frame()->image().properties();
set_display_enabled(true);

const CanvasProperties& props = m_project->get_frame()->image().properties();
m_screen_space_paths_picking_handler->pick(
Vector2i(
result.m_ndc[0] * static_cast<int>(props.m_canvas_width),
Expand All @@ -129,8 +166,9 @@ void LightPathsViewportManager::slot_light_paths_display_toggled(const bool acti

void LightPathsViewportManager::slot_rectangle_selection(const QRect& rect)
{
if (!m_enabled) return;
if (!m_picking_enabled || !m_enabled) return;

set_display_enabled(true);
m_screen_space_paths_picking_handler->pick(
AABB2i(
Vector2i(rect.x(), rect.y()),
Expand All @@ -139,15 +177,17 @@ void LightPathsViewportManager::slot_rectangle_selection(const QRect& rect)

void LightPathsViewportManager::slot_light_path_selection_changed(
const int selected_light_path_index,
const int total_light_paths) const
const int total_light_paths)
{
if (total_light_paths > 0)
{
set_display_enabled(true);
m_prev_path_button->setEnabled(selected_light_path_index > -1);
m_next_path_button->setEnabled(selected_light_path_index < total_light_paths - 1);
}
else
{
set_display_enabled(false);
m_prev_path_button->setEnabled(false);
m_next_path_button->setEnabled(false);
}
Expand All @@ -172,7 +212,7 @@ void LightPathsViewportManager::slot_save_light_paths()
filepath = QDir::toNativeSeparators(filepath);

// Write light paths to disk.
m_project.get_light_path_recorder().write(filepath.toUtf8().constData());
m_project->get_light_path_recorder().write(filepath.toUtf8().constData());
}

void LightPathsViewportManager::slot_camera_changed()
Expand All @@ -192,7 +232,7 @@ void LightPathsViewportManager::create_toolbar()
// Save Light Paths button.
QToolButton* save_light_paths_button = new QToolButton();
save_light_paths_button->setIcon(load_icons("lightpathstab_save_light_paths"));
const auto light_path_count = m_project.get_light_path_recorder().get_light_path_count();
const auto light_path_count = m_project->get_light_path_recorder().get_light_path_count();
save_light_paths_button->setToolTip(
QString("Save %1 Light Path%2...")
.arg(QString::fromStdString(pretty_uint(light_path_count)))
Expand Down Expand Up @@ -233,8 +273,8 @@ void LightPathsViewportManager::create_toolbar()
backface_culling_button->setCheckable(true);
backface_culling_button->setChecked(false);
connect(
backface_culling_button, SIGNAL(toggled()),
light_paths_layer, SLOT(slot_toggle_backface_culling()));
backface_culling_button, SIGNAL(toggled(bool)),
light_paths_layer, SLOT(slot_toggle_backface_culling(bool)));
m_toolbar->addWidget(backface_culling_button);

// Synchronize Camera button.
Expand Down Expand Up @@ -268,7 +308,7 @@ void LightPathsViewportManager::recreate_handlers()
new LightPathsPickingHandler(
m_viewport_tab->get_viewport_widget(),
*m_mouse_tracker.get(),
m_project));
*m_project));
m_screen_space_paths_picking_handler->set_enabled(false);

// The world-space paths picking handler is used to pick paths in the light paths widget.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "mainwindow/rendering/cameracontroller.h"
#include "mainwindow/rendering/lightpathspickinghandler.h"
#include "mainwindow/rendering/renderclipboardhandler.h"
#include "mainwindow/rendering/viewportwidget.h"
#include "utility/mousecoordinatestracker.h"
#include "utility/scrollareapanhandler.h"
#include "utility/widgetzoomhandler.h"
Expand Down Expand Up @@ -72,29 +73,39 @@ class LightPathsViewportManager
public:
LightPathsViewportManager(
ViewportTab* viewport_tab,
renderer::Project& project,
renderer::Project* project,
renderer::ParamArray& settings);

void reset(renderer::Project* project);

QToolBar* toolbar() const;

void set_enabled(const bool enabled);
void set_picking_enabled(const bool enabled);
void set_display_enabled(const bool enabled);

signals:
void signal_should_display(const bool should_display);

public slots:
void slot_entity_picked(const renderer::ScenePicker::PickingResult& result);
void slot_rectangle_selection(const QRect& rect);
void slot_light_paths_display_toggled(const bool active);

private slots:
void slot_base_layer_changed(const ViewportWidget::BaseLayer layer);
void slot_light_path_selection_changed(
const int selected_light_path_index,
const int total_light_paths) const;
const int total_light_paths);
void slot_save_light_paths();
void slot_camera_changed();

private:
bool m_enabled;
bool m_picking_enabled;
bool m_paths_display_active;

renderer::Project& m_project;
renderer::Project* m_project;
renderer::ParamArray& m_settings;
ViewportTab* m_viewport_tab;
QToolBar* m_toolbar;
Expand Down
73 changes: 43 additions & 30 deletions src/appleseed.studio/mainwindow/rendering/viewporttab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#include "mainwindow/project/projectexplorer.h"
#include "mainwindow/rendering/lightpathsviewportmanager.h"
#include "mainwindow/rendering/renderingmanager.h"
#include "mainwindow/rendering/viewportwidget.h"
#include "utility/miscellaneous.h"

// appleseed.renderer headers.
Expand Down Expand Up @@ -93,9 +92,9 @@ ViewportTab::ViewportTab(
layout()->setMargin(0);

create_viewport_widget();
create_light_paths_manager(m_application_settings);
create_toolbar();
create_scrollarea();
create_light_paths_manager();

layout()->addWidget(m_toolbar);
layout()->addWidget(m_light_paths_manager->toolbar());
Expand Down Expand Up @@ -134,7 +133,8 @@ void ViewportTab::render_began()
{
m_viewport_widget->get_render_layer()->darken();
m_viewport_widget->get_light_paths_layer()->update_render_camera_transform();
set_light_paths_enabled(false);
m_light_paths_manager.get()->reset(&m_project);
set_light_paths_toggle_enabled(false);
update();
}

Expand Down Expand Up @@ -176,29 +176,21 @@ void ViewportTab::load_state(const State& state)
m_pan_handler->load_state(state.m_pan_handler_state);
}

void ViewportTab::set_light_paths_enabled(const bool enabled)
void ViewportTab::slot_base_layer_changed(const ViewportWidget::BaseLayer base_layer)
{
m_light_paths_toggle_button->setDisabled(!enabled);
m_light_paths_manager->set_enabled(enabled);
}

void ViewportTab::slot_base_layer_changed(int index)
{
assert(index < ViewportWidget::BaseLayer::BASE_LAYER_MAX_VALUE);
auto base_layer = static_cast<ViewportWidget::BaseLayer>(index);

switch (base_layer)
{
case ViewportWidget::BaseLayer::FinalRender:
if (m_rendering_manager.is_rendering()
&& m_rendering_manager.get_rendering_mode() == RenderingManager::RenderingMode::InteractiveRendering)
case ViewportWidget::BaseLayer::FinalRender:
if (m_rendering_manager.is_rendering()
&& m_rendering_manager.get_rendering_mode() == RenderingManager::RenderingMode::InteractiveRendering)
m_camera_controller.get()->set_enabled(true);
else
m_camera_controller.get()->set_enabled(false);
break;

case ViewportWidget::BaseLayer::OpenGL:
m_camera_controller.get()->set_enabled(true);
else
m_camera_controller.get()->set_enabled(false);
break;
case ViewportWidget::BaseLayer::OpenGL:
m_camera_controller.get()->set_enabled(true);
break;
break;
}
}

Expand Down Expand Up @@ -257,12 +249,25 @@ void ViewportTab::create_viewport_widget()
m_viewport_widget->setMouseTracking(true);
}

void ViewportTab::create_light_paths_manager(renderer::ParamArray application_settings)
void ViewportTab::create_light_paths_manager()
{
m_light_paths_manager = new LightPathsViewportManager(
m_light_paths_manager.reset(new LightPathsViewportManager(
this,
m_project,
application_settings);
&m_project,
m_application_settings));

connect(
m_viewport_widget, SIGNAL(signal_base_layer_changed(const ViewportWidget::BaseLayer)),
m_light_paths_manager.get(), SLOT(slot_base_layer_changed(const ViewportWidget::BaseLayer))
);
connect(
m_light_paths_manager.get(), SIGNAL(signal_should_display(const bool)),
m_viewport_widget, SLOT(slot_light_paths_should_display(const bool))
);
connect(
m_light_paths_toggle_button, SIGNAL(toggled(bool)),
m_light_paths_manager.get(), SLOT(slot_light_paths_display_toggled(bool))
);
}

void ViewportTab::create_toolbar()
Expand All @@ -289,8 +294,8 @@ void ViewportTab::create_toolbar()
m_viewport_widget, SLOT(slot_base_layer_changed(int))
);
connect(
m_base_layer_combo, SIGNAL(activated(int)),
SLOT(slot_base_layer_changed(int))
m_viewport_widget, SIGNAL(signal_base_layer_changed(const ViewportWidget::BaseLayer)),
SLOT(slot_base_layer_changed(const ViewportWidget::BaseLayer))
);

m_light_paths_toggle_button = new QToolButton();
Expand Down Expand Up @@ -548,7 +553,7 @@ void ViewportTab::recreate_handlers()
m_camera_controller.get(), SLOT(slot_entity_picked(renderer::ScenePicker::PickingResult)));
connect(
m_scene_picking_handler.get(), SIGNAL(signal_entity_picked(renderer::ScenePicker::PickingResult)),
m_light_paths_manager, SLOT(slot_entity_picked(renderer::ScenePicker::PickingResult)));
m_light_paths_manager.get(), SLOT(slot_entity_picked(renderer::ScenePicker::PickingResult)));

// Handler for setting render regions with the mouse.
m_viewport_selection_handler.reset(
Expand All @@ -560,7 +565,7 @@ void ViewportTab::recreate_handlers()
SIGNAL(signal_rectangle_selection(const QRect&)));
connect(
m_viewport_selection_handler.get(), SIGNAL(signal_rectangle_selection(const QRect&)),
m_light_paths_manager, SLOT(slot_rectangle_selection(const QRect&)));
m_light_paths_manager.get(), SLOT(slot_rectangle_selection(const QRect&)));
connect(
m_viewport_selection_handler.get(), SIGNAL(signal_render_region(const QRect&)),
SLOT(slot_set_render_region(const QRect&)));
Expand Down Expand Up @@ -590,6 +595,14 @@ void ViewportTab::recreate_handlers()
const QString&)));
}

void ViewportTab::set_light_paths_toggle_enabled(const bool enabled)
{
if (!enabled)
m_light_paths_toggle_button->setChecked(false);

m_light_paths_toggle_button->setDisabled(!enabled);
}

} // namespace studio
} // namespace appleseed

Expand Down
Loading

0 comments on commit 797d142

Please sign in to comment.