Fix objects from hidden layers could still be selected and moved

This commit is contained in:
Florian Rival
2015-08-15 17:33:22 +02:00
parent eab1b352d6
commit 65a1e6bfb5
3 changed files with 35 additions and 2 deletions

View File

@@ -878,6 +878,7 @@ public:
{
gd::InitialInstance & instance = *instancePtr;
if ( ignoreLockedInstances && instance.IsLocked() ) return;
if ( excludedLayers.find(instance.GetLayer()) != excludedLayers.end() ) return;
sf::Vector2f size = editor.GetInitialInstanceSize(instance);
sf::Vector2f origin = editor.GetInitialInstanceOrigin(instance);
@@ -890,13 +891,18 @@ public:
}
}
std::vector<InitialInstance*> & GetSelectedList() { return selectedList; };
InstancesInAreaPicker & IgnoreLockedInstances() { ignoreLockedInstances = true; return *this; };
std::vector<InitialInstance*> & GetSelectedList() { return selectedList; }
InstancesInAreaPicker & IgnoreLockedInstances() { ignoreLockedInstances = true; return *this; }
InstancesInAreaPicker & ExcludeLayer(const gd::String & layerName) {
excludedLayers.insert(layerName);
return *this;
}
private:
const LayoutEditorCanvas & editor;
std::vector<InitialInstance*> selectedList; ///< This list will be filled with the instances that are into the selectionRectangle
bool ignoreLockedInstances;
std::set<gd::String> excludedLayers;
};
void LayoutEditorCanvas::OnLeftUp(wxMouseEvent &)
@@ -967,6 +973,8 @@ void LayoutEditorCanvas::OnLeftUp(wxMouseEvent &)
//Select the instances that are inside the selection rectangle
InstancesInAreaPicker picker(*this);
for(auto hiddenLayer : gd::GetHiddenLayers(layout))
picker.ExcludeLayer(hiddenLayer);
picker.IgnoreLockedInstances();
instances.IterateOverInstances(picker);
@@ -1250,6 +1258,7 @@ public:
{
gd::InitialInstance & instance = *instancePtr;
if ( pickLockedOnly != instance.IsLocked() ) return;
if ( excludedLayers.find(instance.GetLayer()) != excludedLayers.end() ) return;
sf::Vector2f size = editor.GetInitialInstanceSize(instance);
sf::Vector2f origin = editor.GetInitialInstanceOrigin(instance);
@@ -1269,6 +1278,7 @@ public:
InitialInstance * GetSmallestInstanceUnderCursor() { return smallestInstance; };
void PickLockedInstancesAndOnlyThem() { pickLockedOnly = true; }
void ExcludeLayer(const gd::String & layerName) { excludedLayers.insert(layerName); }
private:
const LayoutEditorCanvas & editor;
@@ -1277,11 +1287,15 @@ private:
const double xPosition;
const double yPosition;
bool pickLockedOnly;
std::set<gd::String> excludedLayers;
};
InitialInstance * LayoutEditorCanvas::GetInitialInstanceAtPosition(double xPosition, double yPosition, bool pickOnlyLockedInstances)
{
SmallestInstanceUnderCursorPicker picker(*this, xPosition, yPosition);
for(auto hiddenLayer : gd::GetHiddenLayers(layout))
picker.ExcludeLayer(hiddenLayer);
if ( pickOnlyLockedInstances ) picker.PickLockedInstancesAndOnlyThem();
instances.IterateOverInstances(picker);

View File

@@ -348,6 +348,18 @@ void Layout::Init(const Layout & other)
#endif
}
std::vector<gd::String> GetHiddenLayers(const Layout & layout)
{
std::vector<gd::String> hiddenLayers;
for (unsigned int i = 0;i < layout.GetLayersCount();++i) {
if (!layout.GetLayer(i).GetVisibility()) {
hiddenLayers.push_back(layout.GetLayer(i).GetName());
}
}
return hiddenLayers;
}
#if defined(GD_IDE_ONLY)
gd::String GD_CORE_API GetTypeOfObject(const gd::Project & project, const gd::Layout & layout, gd::String name, bool searchInGroups)
{

View File

@@ -461,6 +461,13 @@ struct LayoutHasName : public std::binary_function<std::shared_ptr<Layout>, gd::
bool operator()(const std::shared_ptr<Layout> & layout, gd::String name) const { return layout->GetName() == name; }
};
/**
* \brief Get the names of all layers from the given layout
* that are invisible.
* \see gd::Layout
*/
std::vector<gd::String> GetHiddenLayers(const Layout & layout);
/**
* \brief Get a type from an object/group name.
* \note If a group contains only objects of a same type, then the group has this type. Otherwise, it is considered as an object without any specific type.