Fixed current source selection behavior with swich to appearance view.

This commit is contained in:
brunoherbelin
2020-11-21 21:29:08 +01:00
parent bb231868b4
commit 59087f9198
5 changed files with 216 additions and 88 deletions

View File

@@ -26,7 +26,7 @@ void DrawVisitor::loop(int num, glm::mat4 transform)
void DrawVisitor::visit(Node &n) void DrawVisitor::visit(Node &n)
{ {
// draw the target // draw the target
if ( n.id() == target_->id()) { if ( target_ && n.id() == target_->id()) {
for (int i = 0; i < num_duplicat_; ++i) { for (int i = 0; i < num_duplicat_; ++i) {
// draw multiple copies if requested // draw multiple copies if requested

View File

@@ -259,7 +259,7 @@ void Source::setMode(Source::Mode m)
(*o).second->visible_ = current; (*o).second->visible_ = current;
// show in appearance view if current // show in appearance view if current
groups_[View::APPEARANCE]->visible_ = current; groups_[View::APPEARANCE]->visible_ = m > Source::VISIBLE;
mode_ = m; mode_ = m;
} }

View File

@@ -535,17 +535,17 @@ void UserInterface::handleMouse()
} }
} }
} }
else if ( ImGui::IsMouseReleased(ImGuiMouseButton_Left) ) // else if ( ImGui::IsMouseReleased(ImGuiMouseButton_Left) )
{ // {
view_drag = nullptr; // view_drag = nullptr;
mousedown = false; // mousedown = false;
picked = { nullptr, glm::vec2(0.f) }; // picked = { nullptr, glm::vec2(0.f) };
Mixer::manager().view()->terminate(); // Mixer::manager().view()->terminate();
// special case of one single source in selection : make current after release // // special case of one single source in selection : make current after release
if (Mixer::selection().size() == 1) // if (Mixer::selection().size() == 1)
Mixer::manager().setCurrentSource( Mixer::selection().front() ); // Mixer::manager().setCurrentSource( Mixer::selection().front() );
} // }
if ( ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left) ) if ( ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left) )
{ {
@@ -630,6 +630,19 @@ void UserInterface::handleMouse()
mousedown = false; mousedown = false;
Mixer::manager().view()->terminate(); Mixer::manager().view()->terminate();
} }
if ( ImGui::IsMouseReleased(ImGuiMouseButton_Left) )
{
view_drag = nullptr;
mousedown = false;
picked = { nullptr, glm::vec2(0.f) };
Mixer::manager().view()->terminate();
// special case of one single source in selection : make current after release
if (Mixer::selection().size() == 1)
Mixer::manager().setCurrentSource( Mixer::selection().front() );
}
} }

228
View.cpp
View File

@@ -603,8 +603,8 @@ uint MixingView::textureMixingQuadratic()
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, CIRCLE_PIXELS, CIRCLE_PIXELS, GL_BGRA, GL_UNSIGNED_BYTE, matrix); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, CIRCLE_PIXELS, CIRCLE_PIXELS, GL_BGRA, GL_UNSIGNED_BYTE, matrix);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
} }
return texid; return texid;
@@ -846,6 +846,7 @@ void GeometryView::draw()
// scene.root()->draw(glm::identity<glm::mat4>(), Rendering::manager().Projection()); // scene.root()->draw(glm::identity<glm::mat4>(), Rendering::manager().Projection());
// re-draw frames of all sources on top // re-draw frames of all sources on top
// (otherwise hidden in stack of sources)
for (auto source_iter = Mixer::manager().session()->begin(); source_iter != Mixer::manager().session()->end(); source_iter++) for (auto source_iter = Mixer::manager().session()->begin(); source_iter != Mixer::manager().session()->end(); source_iter++)
{ {
DrawVisitor dv((*source_iter)->frames_[mode_], Rendering::manager().Projection()); DrawVisitor dv((*source_iter)->frames_[mode_], Rendering::manager().Projection());
@@ -860,6 +861,8 @@ void GeometryView::draw()
scene.accept(dv); scene.accept(dv);
} }
DrawVisitor dv(scene.fg(), Rendering::manager().Projection());
scene.accept(dv);
// display popup menu // display popup menu
if (show_context_menu_) { if (show_context_menu_) {
@@ -1729,7 +1732,7 @@ View::Cursor TransitionView::drag (glm::vec2 from, glm::vec2 to)
} }
AppearanceView::AppearanceView() : View(APPEARANCE), index_source_(-1) AppearanceView::AppearanceView() : View(APPEARANCE), edit_source_(nullptr), need_edit_update_(true)
{ {
// read default settings // read default settings
if ( Settings::application.views[mode_].name.empty() ) { if ( Settings::application.views[mode_].name.empty() ) {
@@ -1805,20 +1808,38 @@ AppearanceView::AppearanceView() : View(APPEARANCE), index_source_(-1)
} }
//void AppearanceView::update(float dt) Source *AppearanceView::EditCurrent()
//{ {
// View::update(dt); Source *current_source = Mixer::manager().currentSource();
// no current source
if (current_source == nullptr) {
// if something can be selected
if ( !Mixer::manager().session()->empty() ) {
// if the edit source exists
if (Mixer::manager().session()->find(edit_source_)!=Mixer::manager().session()->end())
// restore edited source as current
current_source = edit_source_;
else
// pick the first source of the session
current_source = *Mixer::manager().session()->begin();
// apply current source change
Mixer::manager().setCurrentSource(current_source);
}
}
//// // a more complete update is requested (e.g. after switching to view) return current_source;
//// // AND no source selected }
//// if (View::need_deep_update_ && Mixer::manager().indexCurrentSource() < 0) {
//// index_source_ = -1; void AppearanceView::update(float dt)
//// } {
View::update(dt);
// a more complete update is requested (e.g. after switching to view)
if (View::need_deep_update_)
need_edit_update_ = true;
//} }
void AppearanceView::zoom (float factor) void AppearanceView::zoom (float factor)
{ {
@@ -1845,20 +1866,15 @@ int AppearanceView::size ()
} }
//void AppearanceView::selectAll() void AppearanceView::selectAll()
//{ {
//// Mixer::selection().clear(); need_edit_update_ = true;
}
//// Mixer::manager().setCurrentIndex(index_source_); void AppearanceView::select(glm::vec2 A, glm::vec2 B)
{
//// if ( Mixer::manager().currentSource() == nullptr ) need_edit_update_ = true;
//// Mixer::manager().setCurrentNext(); }
//}
//void AppearanceView::select(glm::vec2 A, glm::vec2 B)
//{
//}
std::pair<Node *, glm::vec2> AppearanceView::pick(glm::vec2 P) std::pair<Node *, glm::vec2> AppearanceView::pick(glm::vec2 P)
@@ -1866,14 +1882,82 @@ std::pair<Node *, glm::vec2> AppearanceView::pick(glm::vec2 P)
// get picking from generic View // get picking from generic View
std::pair<Node *, glm::vec2> pick = View::pick(P); std::pair<Node *, glm::vec2> pick = View::pick(P);
Source *picked = nullptr;
Source *s = Mixer::manager().currentSource(); if (pick.first != nullptr) {
if (s != nullptr) {
if ( pick.first == s->handles_[mode_][Handles::MENU] ) { picked = Mixer::manager().findSource(pick.first);
if (picked != nullptr) {
if (picked == edit_source_) {
if (pick.first == edit_source_->handles_[mode_][Handles::MENU] )
// show context menu // show context menu
show_context_menu_ = true; show_context_menu_ = true;
} }
else {
picked = nullptr;
} }
}
}
if (picked == nullptr){
// make sure a source to edit is always picked
picked = EditCurrent();
if (picked)
pick.first = picked->frames_[mode_];
}
// // prepare empty return value
// std::pair<Node *, glm::vec2> pick = { nullptr, glm::vec2(0.f) };
// // unproject mouse coordinate into scene coordinates
// glm::vec3 scene_point_ = Rendering::manager().unProject(P);
// // picking visitor traverses the scene
// PickingVisitor pv(scene_point_);
// scene.accept(pv);
// // picking visitor found nodes?
// if ( !pv.empty() ) {
// // keep edit source active if it is clicked
// Source *s = edit_source_;
// if (s != nullptr) {
// // find if the current source was picked
// auto itp = pv.rbegin();
// for (; itp != pv.rend(); itp++){
// // test if source contains this node
// Source::hasNode is_in_source((*itp).first );
// if ( is_in_source( s ) ){
// // a node in the current source was clicked !
// pick = *itp;
// break;
// }
// }
// // not found: the edit source was not clicked
// if (itp == pv.rend())
// {
// //s = nullptr;
//// Mixer::selection().set(s);
// pick.first = s->frames_[mode_];
// }
// // picking on the edit source
// else {
//// Mixer::selection().clear();
// if ( pick.first == s->handles_[mode_][Handles::MENU] ) // show context menu
// show_context_menu_ = true;
// }
// }
// // no edit source or the clicked source changed
// if (s == nullptr) {
// edit_source_ = EditCurrent();
// if (edit_source_)
// pick.first = edit_source_->frames_[mode_];
// }
// }
// need_edit_update_ = true;
return pick; return pick;
} }
@@ -1881,43 +1965,71 @@ std::pair<Node *, glm::vec2> AppearanceView::pick(glm::vec2 P)
void AppearanceView::draw() void AppearanceView::draw()
{ {
int newindex = Mixer::manager().indexCurrentSource(); // Source *current_source = Mixer::manager().currentSource();
// if ( current_source != edit_source_ )
// {
// // current source is not the edited source
// if (current_source != nullptr) {
// // there is a valid current source, just edit it
// edit_source_ = current_source;
// }
// // no current source, but we have a pointer to source to edit
// else {
// // if the edit source exists?
// if (Mixer::manager().session()->find(edit_source_)!=Mixer::manager().session()->end()) {
// // restore current as current
// Mixer::manager().setCurrentSource(edit_source_);
// }
// else {
// if (Mixer::manager().session()->empty())
// // nothing in the session, nothing to edit
// edit_source_ = nullptr;
// else {
// // pick the first source of the session
// edit_source_ = *Mixer::manager().session()->begin();
// Mixer::manager().setCurrentSource(edit_source_);
// }
// }
// did the current source change? // }
if (index_source_ != newindex) {
// if no source selected // // Update display
if (newindex < 0) { // float scale = 1.f;
// is it because there is no source at all? // surfacepreview->setTextureIndex(0);
if (Mixer::manager().session()->numSource() < 1)
// ok, nothing to display
newindex = -1;
else {
// if we have a valid index, do not change anything
// but make sure it is in the range of valid indices
newindex = CLAMP(index_source_, 0, Mixer::manager().session()->numSource());
}
}
// another index is selected // // if its a valid index
if (index_source_ != newindex) { // if (edit_source_ != nullptr) {
index_source_ = newindex; // // update rendering frame to match edit source AR
// scale = edit_source_->frame()->aspectRatio();
// surfacepreview->setTextureIndex( edit_source_->frame()->texture() );
// }
// reset // // update aspect ratio
// surfacepreview->scale_.x = scale;
// backgroundpreview->scale_.x = scale;
// backgroundpreview->setTextureUV(glm::vec4(0.5f, 0.5f, 64.f * scale, 64.f));
// for (NodeSet::iterator node = scene.fg()->begin(); node != scene.fg()->end(); node++) {
// (*node)->scale_.x = scale;
// }
// }
// a more complete update is requested (e.g. after switching to view)
if ( need_edit_update_ || edit_source_ != Mixer::manager().currentSource()) {
need_edit_update_ = false;
// now, follow the change of current source
// & remember source to edit
edit_source_ = EditCurrent();
// by default consider edit source is null
float scale = 1.f; float scale = 1.f;
surfacepreview->setTextureIndex(0); surfacepreview->setTextureIndex(0);
// if its a valid index // if its a valid index
if (index_source_ > -1) { if (edit_source_ != nullptr) {
// update rendering frame to match edit source AR
Mixer::manager().setCurrentIndex(index_source_); scale = edit_source_->frame()->aspectRatio();
Source *s = Mixer::manager().currentSource(); surfacepreview->setTextureIndex( edit_source_->frame()->texture() );
if (s != nullptr) {
// update rendering frame to match current source AR
scale = s->frame()->aspectRatio();
surfacepreview->setTextureIndex( s->frame()->texture() );
}
} }
// update aspect ratio // update aspect ratio
@@ -1927,7 +2039,7 @@ void AppearanceView::draw()
for (NodeSet::iterator node = scene.fg()->begin(); node != scene.fg()->end(); node++) { for (NodeSet::iterator node = scene.fg()->begin(); node != scene.fg()->end(); node++) {
(*node)->scale_.x = scale; (*node)->scale_.x = scale;
} }
}
} }
Shader::force_blending_opacity = true; Shader::force_blending_opacity = true;

11
View.h
View File

@@ -224,12 +224,12 @@ class AppearanceView : public View
public: public:
AppearanceView(); AppearanceView();
// void select(glm::vec2, glm::vec2) override; void select(glm::vec2, glm::vec2) override;
// void selectAll() override; void selectAll() override;
void draw () override; void draw () override;
// void update (float dt) override; void update (float dt) override;
void zoom (float factor) override; void zoom (float factor) override;
void resize (int) override; void resize (int) override;
int size () override; int size () override;
@@ -241,7 +241,10 @@ public:
private: private:
int index_source_; Source *edit_source_;
bool need_edit_update_;
Source *EditCurrent();
Surface *backgroundpreview; Surface *backgroundpreview;
Surface *surfacepreview; Surface *surfacepreview;