Skip to content

Commit c09120e

Browse files
committed
fix UX bugs with new viewport
1 parent c4bd2f2 commit c09120e

File tree

6 files changed

+123
-61
lines changed

6 files changed

+123
-61
lines changed

src/appleseed.studio/mainwindow/rendering/lightpathsviewportmanager.cpp

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
#include "mainwindow/rendering/lightpathspickinghandler.h"
3434
#include "mainwindow/rendering/lightpathslayer.h"
3535
#include "mainwindow/rendering/viewporttab.h"
36-
#include "mainwindow/rendering/viewportwidget.h"
3736
#include "utility/miscellaneous.h"
3837
#include "utility/settingskeys.h"
3938

@@ -77,9 +76,11 @@ namespace studio {
7776

7877
LightPathsViewportManager::LightPathsViewportManager(
7978
ViewportTab* viewport_tab,
80-
Project& project,
79+
Project* project,
8180
ParamArray& settings)
8281
: m_enabled(false)
82+
, m_picking_enabled(true)
83+
, m_paths_display_active(false)
8384
, m_project(project)
8485
, m_settings(settings)
8586
, m_viewport_tab(viewport_tab)
@@ -94,15 +95,49 @@ LightPathsViewportManager::LightPathsViewportManager(
9495
recreate_handlers();
9596
}
9697

98+
void LightPathsViewportManager::reset(renderer::Project* project)
99+
{
100+
set_enabled(false);
101+
set_display_enabled(false);
102+
set_picking_enabled(true);
103+
m_project = project;
104+
}
105+
106+
void LightPathsViewportManager::slot_base_layer_changed(const ViewportWidget::BaseLayer layer)
107+
{
108+
if (layer == ViewportWidget::BaseLayer::FinalRender)
109+
set_picking_enabled(true);
110+
else
111+
set_picking_enabled(false);
112+
}
113+
97114
void LightPathsViewportManager::set_enabled(const bool enabled)
98115
{
99116
m_enabled = enabled;
100117
if (enabled)
118+
{
101119
m_toolbar->show();
120+
}
102121
else
122+
{
123+
set_display_enabled(false);
103124
m_toolbar->hide();
104-
125+
}
105126
m_toolbar->setDisabled(!enabled);
127+
128+
emit signal_should_display(m_enabled && m_paths_display_active);
129+
}
130+
131+
void LightPathsViewportManager::set_display_enabled(const bool enabled)
132+
{
133+
m_paths_display_active = enabled;
134+
135+
emit signal_should_display(m_enabled && m_paths_display_active);
136+
}
137+
138+
void LightPathsViewportManager::set_picking_enabled(const bool enabled)
139+
{
140+
m_picking_enabled = enabled;
106141
m_screen_space_paths_picking_handler->set_enabled(enabled);
107142
}
108143

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

114149
void LightPathsViewportManager::slot_entity_picked(const ScenePicker::PickingResult& result)
115150
{
116-
if (!m_enabled) return;
151+
if (!m_picking_enabled || !m_enabled) return;
117152

118-
const CanvasProperties& props = m_project.get_frame()->image().properties();
153+
set_display_enabled(true);
154+
155+
const CanvasProperties& props = m_project->get_frame()->image().properties();
119156
m_screen_space_paths_picking_handler->pick(
120157
Vector2i(
121158
result.m_ndc[0] * static_cast<int>(props.m_canvas_width),
@@ -129,8 +166,9 @@ void LightPathsViewportManager::slot_light_paths_display_toggled(const bool acti
129166

130167
void LightPathsViewportManager::slot_rectangle_selection(const QRect& rect)
131168
{
132-
if (!m_enabled) return;
169+
if (!m_picking_enabled || !m_enabled) return;
133170

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

140178
void LightPathsViewportManager::slot_light_path_selection_changed(
141179
const int selected_light_path_index,
142-
const int total_light_paths) const
180+
const int total_light_paths)
143181
{
144182
if (total_light_paths > 0)
145183
{
184+
set_display_enabled(true);
146185
m_prev_path_button->setEnabled(selected_light_path_index > -1);
147186
m_next_path_button->setEnabled(selected_light_path_index < total_light_paths - 1);
148187
}
149188
else
150189
{
190+
set_display_enabled(false);
151191
m_prev_path_button->setEnabled(false);
152192
m_next_path_button->setEnabled(false);
153193
}
@@ -172,7 +212,7 @@ void LightPathsViewportManager::slot_save_light_paths()
172212
filepath = QDir::toNativeSeparators(filepath);
173213

174214
// Write light paths to disk.
175-
m_project.get_light_path_recorder().write(filepath.toUtf8().constData());
215+
m_project->get_light_path_recorder().write(filepath.toUtf8().constData());
176216
}
177217

178218
void LightPathsViewportManager::slot_camera_changed()
@@ -192,7 +232,7 @@ void LightPathsViewportManager::create_toolbar()
192232
// Save Light Paths button.
193233
QToolButton* save_light_paths_button = new QToolButton();
194234
save_light_paths_button->setIcon(load_icons("lightpathstab_save_light_paths"));
195-
const auto light_path_count = m_project.get_light_path_recorder().get_light_path_count();
235+
const auto light_path_count = m_project->get_light_path_recorder().get_light_path_count();
196236
save_light_paths_button->setToolTip(
197237
QString("Save %1 Light Path%2...")
198238
.arg(QString::fromStdString(pretty_uint(light_path_count)))
@@ -233,8 +273,8 @@ void LightPathsViewportManager::create_toolbar()
233273
backface_culling_button->setCheckable(true);
234274
backface_culling_button->setChecked(false);
235275
connect(
236-
backface_culling_button, SIGNAL(toggled()),
237-
light_paths_layer, SLOT(slot_toggle_backface_culling()));
276+
backface_culling_button, SIGNAL(toggled(bool)),
277+
light_paths_layer, SLOT(slot_toggle_backface_culling(bool)));
238278
m_toolbar->addWidget(backface_culling_button);
239279

240280
// Synchronize Camera button.
@@ -268,7 +308,7 @@ void LightPathsViewportManager::recreate_handlers()
268308
new LightPathsPickingHandler(
269309
m_viewport_tab->get_viewport_widget(),
270310
*m_mouse_tracker.get(),
271-
m_project));
311+
*m_project));
272312
m_screen_space_paths_picking_handler->set_enabled(false);
273313

274314
// The world-space paths picking handler is used to pick paths in the light paths widget.

src/appleseed.studio/mainwindow/rendering/lightpathsviewportmanager.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "mainwindow/rendering/cameracontroller.h"
3333
#include "mainwindow/rendering/lightpathspickinghandler.h"
3434
#include "mainwindow/rendering/renderclipboardhandler.h"
35+
#include "mainwindow/rendering/viewportwidget.h"
3536
#include "utility/mousecoordinatestracker.h"
3637
#include "utility/scrollareapanhandler.h"
3738
#include "utility/widgetzoomhandler.h"
@@ -72,29 +73,39 @@ class LightPathsViewportManager
7273
public:
7374
LightPathsViewportManager(
7475
ViewportTab* viewport_tab,
75-
renderer::Project& project,
76+
renderer::Project* project,
7677
renderer::ParamArray& settings);
7778

79+
void reset(renderer::Project* project);
80+
7881
QToolBar* toolbar() const;
7982

8083
void set_enabled(const bool enabled);
84+
void set_picking_enabled(const bool enabled);
85+
void set_display_enabled(const bool enabled);
86+
87+
signals:
88+
void signal_should_display(const bool should_display);
8189

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

8795
private slots:
96+
void slot_base_layer_changed(const ViewportWidget::BaseLayer layer);
8897
void slot_light_path_selection_changed(
8998
const int selected_light_path_index,
90-
const int total_light_paths) const;
99+
const int total_light_paths);
91100
void slot_save_light_paths();
92101
void slot_camera_changed();
93102

94103
private:
95104
bool m_enabled;
105+
bool m_picking_enabled;
106+
bool m_paths_display_active;
96107

97-
renderer::Project& m_project;
108+
renderer::Project* m_project;
98109
renderer::ParamArray& m_settings;
99110
ViewportTab* m_viewport_tab;
100111
QToolBar* m_toolbar;

src/appleseed.studio/mainwindow/rendering/viewporttab.cpp

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
#include "mainwindow/project/projectexplorer.h"
3535
#include "mainwindow/rendering/lightpathsviewportmanager.h"
3636
#include "mainwindow/rendering/renderingmanager.h"
37-
#include "mainwindow/rendering/viewportwidget.h"
3837
#include "utility/miscellaneous.h"
3938

4039
// appleseed.renderer headers.
@@ -93,9 +92,9 @@ ViewportTab::ViewportTab(
9392
layout()->setMargin(0);
9493

9594
create_viewport_widget();
96-
create_light_paths_manager(m_application_settings);
9795
create_toolbar();
9896
create_scrollarea();
97+
create_light_paths_manager();
9998

10099
layout()->addWidget(m_toolbar);
101100
layout()->addWidget(m_light_paths_manager->toolbar());
@@ -134,7 +133,8 @@ void ViewportTab::render_began()
134133
{
135134
m_viewport_widget->get_render_layer()->darken();
136135
m_viewport_widget->get_light_paths_layer()->update_render_camera_transform();
137-
set_light_paths_enabled(false);
136+
m_light_paths_manager.get()->reset(&m_project);
137+
set_light_paths_toggle_enabled(false);
138138
update();
139139
}
140140

@@ -176,29 +176,21 @@ void ViewportTab::load_state(const State& state)
176176
m_pan_handler->load_state(state.m_pan_handler_state);
177177
}
178178

179-
void ViewportTab::set_light_paths_enabled(const bool enabled)
179+
void ViewportTab::slot_base_layer_changed(const ViewportWidget::BaseLayer base_layer)
180180
{
181-
m_light_paths_toggle_button->setDisabled(!enabled);
182-
m_light_paths_manager->set_enabled(enabled);
183-
}
184-
185-
void ViewportTab::slot_base_layer_changed(int index)
186-
{
187-
assert(index < ViewportWidget::BaseLayer::BASE_LAYER_MAX_VALUE);
188-
auto base_layer = static_cast<ViewportWidget::BaseLayer>(index);
189-
190181
switch (base_layer)
191182
{
192-
case ViewportWidget::BaseLayer::FinalRender:
193-
if (m_rendering_manager.is_rendering()
194-
&& m_rendering_manager.get_rendering_mode() == RenderingManager::RenderingMode::InteractiveRendering)
183+
case ViewportWidget::BaseLayer::FinalRender:
184+
if (m_rendering_manager.is_rendering()
185+
&& m_rendering_manager.get_rendering_mode() == RenderingManager::RenderingMode::InteractiveRendering)
186+
m_camera_controller.get()->set_enabled(true);
187+
else
188+
m_camera_controller.get()->set_enabled(false);
189+
break;
190+
191+
case ViewportWidget::BaseLayer::OpenGL:
195192
m_camera_controller.get()->set_enabled(true);
196-
else
197-
m_camera_controller.get()->set_enabled(false);
198-
break;
199-
case ViewportWidget::BaseLayer::OpenGL:
200-
m_camera_controller.get()->set_enabled(true);
201-
break;
193+
break;
202194
}
203195
}
204196

@@ -257,12 +249,25 @@ void ViewportTab::create_viewport_widget()
257249
m_viewport_widget->setMouseTracking(true);
258250
}
259251

260-
void ViewportTab::create_light_paths_manager(renderer::ParamArray application_settings)
252+
void ViewportTab::create_light_paths_manager()
261253
{
262-
m_light_paths_manager = new LightPathsViewportManager(
254+
m_light_paths_manager.reset(new LightPathsViewportManager(
263255
this,
264-
m_project,
265-
application_settings);
256+
&m_project,
257+
m_application_settings));
258+
259+
connect(
260+
m_viewport_widget, SIGNAL(signal_base_layer_changed(const ViewportWidget::BaseLayer)),
261+
m_light_paths_manager.get(), SLOT(slot_base_layer_changed(const ViewportWidget::BaseLayer))
262+
);
263+
connect(
264+
m_light_paths_manager.get(), SIGNAL(signal_should_display(const bool)),
265+
m_viewport_widget, SLOT(slot_light_paths_should_display(const bool))
266+
);
267+
connect(
268+
m_light_paths_toggle_button, SIGNAL(toggled(bool)),
269+
m_light_paths_manager.get(), SLOT(slot_light_paths_display_toggled(bool))
270+
);
266271
}
267272

268273
void ViewportTab::create_toolbar()
@@ -289,8 +294,8 @@ void ViewportTab::create_toolbar()
289294
m_viewport_widget, SLOT(slot_base_layer_changed(int))
290295
);
291296
connect(
292-
m_base_layer_combo, SIGNAL(activated(int)),
293-
SLOT(slot_base_layer_changed(int))
297+
m_viewport_widget, SIGNAL(signal_base_layer_changed(const ViewportWidget::BaseLayer)),
298+
SLOT(slot_base_layer_changed(const ViewportWidget::BaseLayer))
294299
);
295300

296301
m_light_paths_toggle_button = new QToolButton();
@@ -548,7 +553,7 @@ void ViewportTab::recreate_handlers()
548553
m_camera_controller.get(), SLOT(slot_entity_picked(renderer::ScenePicker::PickingResult)));
549554
connect(
550555
m_scene_picking_handler.get(), SIGNAL(signal_entity_picked(renderer::ScenePicker::PickingResult)),
551-
m_light_paths_manager, SLOT(slot_entity_picked(renderer::ScenePicker::PickingResult)));
556+
m_light_paths_manager.get(), SLOT(slot_entity_picked(renderer::ScenePicker::PickingResult)));
552557

553558
// Handler for setting render regions with the mouse.
554559
m_viewport_selection_handler.reset(
@@ -560,7 +565,7 @@ void ViewportTab::recreate_handlers()
560565
SIGNAL(signal_rectangle_selection(const QRect&)));
561566
connect(
562567
m_viewport_selection_handler.get(), SIGNAL(signal_rectangle_selection(const QRect&)),
563-
m_light_paths_manager, SLOT(slot_rectangle_selection(const QRect&)));
568+
m_light_paths_manager.get(), SLOT(slot_rectangle_selection(const QRect&)));
564569
connect(
565570
m_viewport_selection_handler.get(), SIGNAL(signal_render_region(const QRect&)),
566571
SLOT(slot_set_render_region(const QRect&)));
@@ -590,6 +595,14 @@ void ViewportTab::recreate_handlers()
590595
const QString&)));
591596
}
592597

598+
void ViewportTab::set_light_paths_toggle_enabled(const bool enabled)
599+
{
600+
if (!enabled)
601+
m_light_paths_toggle_button->setChecked(false);
602+
603+
m_light_paths_toggle_button->setDisabled(!enabled);
604+
}
605+
593606
} // namespace studio
594607
} // namespace appleseed
595608

0 commit comments

Comments
 (0)