mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-05 15:30:00 +01:00
Fixed UserInterface selection of multiple sources. Cleared code for
Source searching by nodes pointers.
This commit is contained in:
@@ -366,7 +366,7 @@ void Mixer::renameSource(Source *s, const std::string &newname)
|
||||
// search for a source of the name 'tentativename'
|
||||
std::string basename = tentativename;
|
||||
int count = 1;
|
||||
while ( std::find_if(session_->begin(), session_->end(), hasName(tentativename)) != session_->end() ) {
|
||||
while ( std::find_if(session_->begin(), session_->end(), Source::hasName(tentativename)) != session_->end() ) {
|
||||
tentativename = basename + std::to_string(++count);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,13 +10,16 @@ SearchVisitor::SearchVisitor(Node *node) : Visitor(), node_(node), found_(false)
|
||||
|
||||
void SearchVisitor::visit(Node &n)
|
||||
{
|
||||
if ( node_ == &n ){
|
||||
if ( !found_ && node_ == &n ){
|
||||
found_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
void SearchVisitor::visit(Group &n)
|
||||
{
|
||||
if (found_)
|
||||
return;
|
||||
|
||||
for (NodeSet::iterator node = n.begin(); node != n.end(); node++) {
|
||||
(*node)->accept(*this);
|
||||
if (found_)
|
||||
|
||||
@@ -21,6 +21,8 @@ void Selection::set(SourceList l)
|
||||
for(auto it = l.begin(); it != l.end(); it++)
|
||||
(*it)->setMode(Source::ACTIVE);
|
||||
|
||||
l.sort();
|
||||
l.unique();
|
||||
selection_ = l;
|
||||
}
|
||||
|
||||
@@ -32,7 +34,10 @@ void Selection::add(SourceList l)
|
||||
// generate new set as union of current selection and give list
|
||||
SourceList result;
|
||||
std::set_union(selection_.begin(), selection_.end(), l.begin(), l.end(), std::inserter(result, result.begin()) );
|
||||
|
||||
// set new selection
|
||||
result.sort();
|
||||
result.unique();
|
||||
selection_ = SourceList(result);
|
||||
}
|
||||
|
||||
@@ -65,6 +70,11 @@ void Selection::clear()
|
||||
selection_.clear();
|
||||
}
|
||||
|
||||
uint Selection::size()
|
||||
{
|
||||
return selection_.size();
|
||||
}
|
||||
|
||||
SourceList::iterator Selection::find(Source *s)
|
||||
{
|
||||
return std::find(selection_.begin(), selection_.end(), s);
|
||||
|
||||
@@ -16,6 +16,7 @@ public:
|
||||
|
||||
void set (SourceList l);
|
||||
void clear ();
|
||||
uint size ();
|
||||
|
||||
SourceList::iterator begin ();
|
||||
SourceList::iterator end ();
|
||||
|
||||
@@ -151,12 +151,12 @@ SourceList::iterator Session::find(Source *s)
|
||||
|
||||
SourceList::iterator Session::find(std::string namesource)
|
||||
{
|
||||
return std::find_if(sources_.begin(), sources_.end(), hasName(namesource));
|
||||
return std::find_if(sources_.begin(), sources_.end(), Source::hasName(namesource));
|
||||
}
|
||||
|
||||
SourceList::iterator Session::find(Node *node)
|
||||
{
|
||||
return std::find_if(sources_.begin(), sources_.end(), hasNode(node));
|
||||
return std::find_if(sources_.begin(), sources_.end(), Source::hasNode(node));
|
||||
}
|
||||
|
||||
uint Session::numSource() const
|
||||
|
||||
23
Source.cpp
23
Source.cpp
@@ -275,22 +275,21 @@ bool Source::contains(Node *node) const
|
||||
}
|
||||
|
||||
|
||||
bool hasNode::operator()(const Source* elem) const
|
||||
bool Source::hasNode::operator()(const Source* elem) const
|
||||
{
|
||||
if (_n && elem)
|
||||
{
|
||||
// quick case (most frequent and easy to answer)
|
||||
if (elem->rendersurface_ == _n)
|
||||
return true;
|
||||
|
||||
// general case: traverse tree of all Groups recursively using a SearchVisitor
|
||||
SearchVisitor sv(_n);
|
||||
elem->group(View::MIXING)->accept(sv);
|
||||
if (sv.found())
|
||||
return true;
|
||||
elem->group(View::GEOMETRY)->accept(sv);
|
||||
if (sv.found())
|
||||
return true;
|
||||
elem->group(View::LAYER)->accept(sv);
|
||||
if (sv.found())
|
||||
return true;
|
||||
elem->group(View::RENDERING)->accept(sv);
|
||||
return sv.found();
|
||||
for (auto g = elem->groups_.begin(); g != elem->groups_.end(); g++) {
|
||||
(*g).second->accept(sv);
|
||||
if (sv.found())
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
38
Source.h
38
Source.h
@@ -85,6 +85,25 @@ public:
|
||||
// a Source shall define how to render into the frame buffer
|
||||
virtual void render() = 0;
|
||||
|
||||
|
||||
struct hasNode: public std::unary_function<Source*, bool>
|
||||
{
|
||||
bool operator()(const Source* elem) const;
|
||||
hasNode(Node *n) : _n(n) { }
|
||||
private:
|
||||
Node *_n;
|
||||
};
|
||||
|
||||
struct hasName: public std::unary_function<Source*, bool>
|
||||
{
|
||||
inline bool operator()(const Source* elem) const {
|
||||
return (elem && elem->name() == _n);
|
||||
}
|
||||
hasName(std::string n) : _n(n) { }
|
||||
private:
|
||||
std::string _n;
|
||||
};
|
||||
|
||||
protected:
|
||||
// name
|
||||
std::string name_;
|
||||
@@ -128,25 +147,6 @@ protected:
|
||||
CloneList clones_;
|
||||
};
|
||||
|
||||
struct hasName: public std::unary_function<Source*, bool>
|
||||
{
|
||||
inline bool operator()(const Source* elem) const {
|
||||
return (elem && elem->name() == _n);
|
||||
}
|
||||
hasName(std::string n) : _n(n) { }
|
||||
|
||||
private:
|
||||
std::string _n;
|
||||
};
|
||||
|
||||
struct hasNode: public std::unary_function<Source*, bool>
|
||||
{
|
||||
bool operator()(const Source* elem) const;
|
||||
hasNode(Node *n) : _n(n) { }
|
||||
|
||||
private:
|
||||
Node *_n;
|
||||
};
|
||||
|
||||
|
||||
class CloneSource : public Source
|
||||
|
||||
9
View.cpp
9
View.cpp
@@ -120,16 +120,19 @@ void View::select(glm::vec2 A, glm::vec2 B)
|
||||
// picking visitor found nodes in the area?
|
||||
if ( !pv.picked().empty()) {
|
||||
|
||||
// create a list of source matching the list of picked nodes
|
||||
SourceList selection;
|
||||
for(auto p = pv.picked().begin(); p != pv.picked().end(); p++){
|
||||
std::vector< std::pair<Node *, glm::vec2> > pick = pv.picked();
|
||||
// loop over the nodes and add all sources found.
|
||||
for(std::vector< std::pair<Node *, glm::vec2> >::iterator p = pick.begin(); p != pick.end(); p++){
|
||||
Source *s = Mixer::manager().findSource( p->first );
|
||||
if (s)
|
||||
selection.push_back( s );
|
||||
}
|
||||
// set the selection with list of picked (overlaped) sources
|
||||
Mixer::selection().add(selection);
|
||||
|
||||
Mixer::selection().set(selection);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user