Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#5235: Implement "SelectItemsByModel" & "DeselectItemsByModel" commands
- Loading branch information
1 parent
1afb5a9
commit be81e5e
Showing
6 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#pragma once | ||
|
||
#include "inode.h" | ||
#include "ientity.h" | ||
#include "iselectable.h" | ||
|
||
namespace scene | ||
{ | ||
|
||
/** | ||
* Scene walker (de-)selecting all entities | ||
* matching the predicate passed to the constructor. | ||
*/ | ||
class EntitySelector : | ||
public scene::NodeVisitor | ||
{ | ||
private: | ||
std::function<bool(const Entity&)> _predicate; | ||
bool _select; | ||
|
||
public: | ||
EntitySelector(const std::function<bool(const Entity&)>& predicate, bool select) : | ||
_predicate(predicate), | ||
_select(select) | ||
{} | ||
|
||
bool pre(const scene::INodePtr& node) override | ||
{ | ||
if (!Node_isEntity(node)) | ||
{ | ||
return true; | ||
} | ||
|
||
const auto* entity = Node_getEntity(node); | ||
assert(entity != nullptr); | ||
|
||
if (_predicate(*entity)) | ||
{ | ||
Node_setSelected(node, _select); | ||
} | ||
|
||
return false; // don't go deeper | ||
} | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters