1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Minor clean-ups.

This commit is contained in:
jules 2013-09-07 16:46:22 +01:00
parent 25291038b8
commit 5df6bf0513
6 changed files with 72 additions and 74 deletions

View file

@ -61,7 +61,7 @@ public:
the set so that your UI objects will know when the selection changes and
be able to update themselves appropriately.
*/
virtual SelectedItemSet <SelectableItemType>& getLassoSelection() = 0;
virtual SelectedItemSet<SelectableItemType>& getLassoSelection() = 0;
};
@ -102,11 +102,6 @@ public:
{
}
/** Destructor. */
~LassoComponent()
{
}
//==============================================================================
/** Call this in your mouseDown event, to initialise a drag.
@ -118,8 +113,7 @@ public:
@see dragLasso, endLasso, LassoSource
*/
void beginLasso (const MouseEvent& e,
LassoSource <SelectableItemType>* const lassoSource)
void beginLasso (const MouseEvent& e, LassoSource<SelectableItemType>* lassoSource)
{
jassert (source == nullptr); // this suggests that you didn't call endLasso() after the last drag...
jassert (lassoSource != nullptr); // the source can't be null!
@ -153,7 +147,7 @@ public:
setBounds (Rectangle<int> (dragStartPos, e.getPosition()));
setVisible (true);
Array <SelectableItemType> itemsInLasso;
Array<SelectableItemType> itemsInLasso;
source->findLassoItemsInArea (itemsInLasso, getBounds());
if (e.mods.isShiftDown())
@ -163,19 +157,18 @@ public:
}
else if (e.mods.isCommandDown() || e.mods.isAltDown())
{
Array <SelectableItemType> originalMinusNew (originalSelection);
Array<SelectableItemType> originalMinusNew (originalSelection);
originalMinusNew.removeValuesIn (itemsInLasso);
itemsInLasso.removeValuesIn (originalSelection);
itemsInLasso.addArray (originalMinusNew);
}
source->getLassoSelection() = SelectedItemSet <SelectableItemType> (itemsInLasso);
source->getLassoSelection() = SelectedItemSet<SelectableItemType> (itemsInLasso);
}
}
/** Call this in your mouseUp event, after the lasso has been dragged.
@see beginLasso, dragLasso
*/
void endLasso()
@ -219,8 +212,8 @@ public:
private:
//==============================================================================
Array <SelectableItemType> originalSelection;
LassoSource <SelectableItemType>* source;
Array<SelectableItemType> originalSelection;
LassoSource<SelectableItemType>* source;
Point<int> dragStartPos;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LassoComponent)

View file

@ -47,6 +47,7 @@ class SelectedItemSet : public ChangeBroadcaster
public:
//==============================================================================
typedef SelectableItemType ItemType;
typedef Array<SelectableItemType> ItemArray;
typedef PARAMETER_TYPE (SelectableItemType) ParameterType;
//==============================================================================
@ -56,7 +57,7 @@ public:
}
/** Creates a set based on an array of items. */
explicit SelectedItemSet (const Array <SelectableItemType>& items)
explicit SelectedItemSet (const ItemArray& items)
: selectedItems (items)
{
}
@ -247,30 +248,25 @@ public:
/** Returns the number of currently selected items.
@see getSelectedItem
*/
int getNumSelected() const noexcept
{
return selectedItems.size();
}
int getNumSelected() const noexcept { return selectedItems.size(); }
/** Returns one of the currently selected items.
Returns 0 if the index is out-of-range.
If the index is out-of-range, this returns a default-constructed SelectableItemType.
@see getNumSelected
*/
SelectableItemType getSelectedItem (const int index) const noexcept
{
return selectedItems [index];
}
SelectableItemType getSelectedItem (const int index) const { return selectedItems [index]; }
/** True if this item is currently selected. */
bool isSelected (ParameterType item) const noexcept
{
return selectedItems.contains (item);
}
bool isSelected (ParameterType item) const noexcept { return selectedItems.contains (item); }
const Array <SelectableItemType>& getItemArray() const noexcept { return selectedItems; }
/** Provides access to the array of items. */
const ItemArray& getItemArray() const noexcept { return selectedItems; }
SelectableItemType* begin() const noexcept { return selectedItems.begin(); }
SelectableItemType* end() const noexcept { return selectedItems.end(); }
/** Provides iterator access to the array of items. */
SelectableItemType* begin() const noexcept { return selectedItems.begin(); }
/** Provides iterator access to the array of items. */
SelectableItemType* end() const noexcept { return selectedItems.end(); }
//==============================================================================
/** Can be overridden to do special handling when an item is selected.
@ -278,17 +274,27 @@ public:
For example, if the item is an object, you might want to call it and tell
it that it's being selected.
*/
virtual void itemSelected (SelectableItemType item) { (void) item; }
virtual void itemSelected (SelectableItemType) {}
/** Can be overridden to do special handling when an item is deselected.
For example, if the item is an object, you might want to call it and tell
it that it's being deselected.
*/
virtual void itemDeselected (SelectableItemType item) { (void) item; }
virtual void itemDeselected (SelectableItemType) {}
/** Used internally, but can be called to force a change message to be sent to the ChangeListeners. */
void changed (const bool synchronous = false)
/** Used internally, but can be called to force a change message to be sent
to the ChangeListeners.
*/
void changed()
{
sendChangeMessage();
}
/** Used internally, but can be called to force a change message to be sent
to the ChangeListeners.
*/
void changed (const bool synchronous)
{
if (synchronous)
sendSynchronousChangeMessage();
@ -298,9 +304,9 @@ public:
private:
//==============================================================================
Array <SelectableItemType> selectedItems;
ItemArray selectedItems;
JUCE_LEAK_DETECTOR (SelectedItemSet <SelectableItemType>)
JUCE_LEAK_DETECTOR (SelectedItemSet<SelectableItemType>)
};