Browse Source

Minor clean-ups.

tags/2021-05-28
jules 12 years ago
parent
commit
5df6bf0513
6 changed files with 72 additions and 74 deletions
  1. +5
    -5
      modules/juce_core/containers/juce_Array.h
  2. +2
    -1
      modules/juce_core/xml/juce_XmlDocument.cpp
  3. +22
    -23
      modules/juce_graphics/native/juce_RenderingHelpers.h
  4. +7
    -8
      modules/juce_gui_basics/commands/juce_ApplicationCommandTarget.cpp
  5. +7
    -14
      modules/juce_gui_basics/mouse/juce_LassoComponent.h
  6. +29
    -23
      modules/juce_gui_basics/mouse/juce_SelectedItemSet.h

+ 5
- 5
modules/juce_core/containers/juce_Array.h View File

@@ -715,7 +715,7 @@ public:
@param indexToRemove the index of the element to remove @param indexToRemove the index of the element to remove
@returns the element that has been removed @returns the element that has been removed
@see removeValue, removeRange
@see removeFirstMatchingValue, removeAllInstancesOf, removeRange
*/ */
ElementType remove (const int indexToRemove) ElementType remove (const int indexToRemove)
{ {
@@ -782,7 +782,7 @@ public:
@param startIndex the index of the first element to remove @param startIndex the index of the first element to remove
@param numberToRemove how many elements should be removed @param numberToRemove how many elements should be removed
@see remove, removeValue
@see remove, removeFirstMatchingValue, removeAllInstancesOf
*/ */
void removeRange (int startIndex, int numberToRemove) void removeRange (int startIndex, int numberToRemove)
{ {
@@ -810,7 +810,7 @@ public:
/** Removes the last n elements from the array. /** Removes the last n elements from the array.
@param howManyToRemove how many elements to remove from the end of the array @param howManyToRemove how many elements to remove from the end of the array
@see remove, removeValue, removeRange
@see remove, removeFirstMatchingValue, removeAllInstancesOf, removeRange
*/ */
void removeLast (int howManyToRemove = 1) void removeLast (int howManyToRemove = 1)
{ {
@@ -829,7 +829,7 @@ public:
/** Removes any elements which are also in another array. /** Removes any elements which are also in another array.
@param otherArray the other array in which to look for elements to remove @param otherArray the other array in which to look for elements to remove
@see removeValuesNotIn, remove, removeValue, removeRange
@see removeValuesNotIn, remove, removeFirstMatchingValue, removeAllInstancesOf, removeRange
*/ */
template <class OtherArrayType> template <class OtherArrayType>
void removeValuesIn (const OtherArrayType& otherArray) void removeValuesIn (const OtherArrayType& otherArray)
@@ -857,7 +857,7 @@ public:
Only elements which occur in this other array will be retained. Only elements which occur in this other array will be retained.
@param otherArray the array in which to look for elements NOT to remove @param otherArray the array in which to look for elements NOT to remove
@see removeValuesIn, remove, removeValue, removeRange
@see removeValuesIn, remove, removeFirstMatchingValue, removeAllInstancesOf, removeRange
*/ */
template <class OtherArrayType> template <class OtherArrayType>
void removeValuesNotIn (const OtherArrayType& otherArray) void removeValuesNotIn (const OtherArrayType& otherArray)


+ 2
- 1
modules/juce_core/xml/juce_XmlDocument.cpp View File

@@ -312,7 +312,8 @@ void XmlDocument::skipNextWhiteSpace()
input += closeComment + 3; input += closeComment + 3;
continue; continue;
} }
else if (input[1] == '?')
if (input[1] == '?')
{ {
input += 2; input += 2;
const int closeBracket = input.indexOf (CharPointer_ASCII ("?>")); const int closeBracket = input.indexOf (CharPointer_ASCII ("?>"));


+ 22
- 23
modules/juce_graphics/native/juce_RenderingHelpers.h View File

@@ -52,13 +52,13 @@ public:
AffineTransform getTransform() const noexcept AffineTransform getTransform() const noexcept
{ {
return isOnlyTranslated ? AffineTransform::translation ((float) offset.x, (float) offset.y)
return isOnlyTranslated ? AffineTransform::translation (offset)
: complexTransform; : complexTransform;
} }
AffineTransform getTransformWith (const AffineTransform& userTransform) const noexcept AffineTransform getTransformWith (const AffineTransform& userTransform) const noexcept
{ {
return isOnlyTranslated ? userTransform.translated ((float) offset.x, (float) offset.y)
return isOnlyTranslated ? userTransform.translated (offset)
: userTransform.followedBy (complexTransform); : userTransform.followedBy (complexTransform);
} }
@@ -67,7 +67,7 @@ public:
if (isOnlyTranslated) if (isOnlyTranslated)
offset += delta; offset += delta;
else else
complexTransform = AffineTransform::translation ((float) delta.x, (float) delta.y)
complexTransform = AffineTransform::translation (delta)
.followedBy (complexTransform); .followedBy (complexTransform);
} }
@@ -75,15 +75,19 @@ public:
{ {
if (isOnlyTranslated && t.isOnlyTranslation()) if (isOnlyTranslated && t.isOnlyTranslation())
{ {
offset += Point<int> ((int) t.getTranslationX(),
(int) t.getTranslationY());
}
else
{
complexTransform = getTransformWith (t);
isOnlyTranslated = false;
isRotated = (complexTransform.mat01 != 0 || complexTransform.mat10 != 0);
const int tx = (int) (t.getTranslationX() * 256.0f);
const int ty = (int) (t.getTranslationY() * 256.0f);
if (((tx | ty) & 0xf8) == 0)
{
offset += Point<int> (tx >> 8, ty >> 8);
return;
}
} }
complexTransform = getTransformWith (t);
isOnlyTranslated = false;
isRotated = (complexTransform.mat01 != 0 || complexTransform.mat10 != 0);
} }
float getPhysicalPixelScaleFactor() const noexcept float getPhysicalPixelScaleFactor() const noexcept
@@ -96,7 +100,7 @@ public:
if (isOnlyTranslated) if (isOnlyTranslated)
offset += delta; offset += delta;
else else
complexTransform = complexTransform.translated ((float) delta.x, (float) delta.y);
complexTransform = complexTransform.translated (delta);
} }
Rectangle<int> translated (const Rectangle<int>& r) const noexcept Rectangle<int> translated (const Rectangle<int>& r) const noexcept
@@ -1004,7 +1008,8 @@ namespace EdgeTableFillers
++dest; ++dest;
continue; continue;
} }
else if (! repeatPattern)
if (! repeatPattern)
{ {
// At a top or bottom edge.. // At a top or bottom edge..
if (loResY < 0) if (loResY < 0)
@@ -1284,9 +1289,9 @@ namespace EdgeTableFillers
public: public:
BresenhamInterpolator() noexcept {} BresenhamInterpolator() noexcept {}
void set (const int n1, const int n2, const int numSteps_, const int offsetInt) noexcept
void set (const int n1, const int n2, const int steps, const int offsetInt) noexcept
{ {
numSteps = numSteps_;
numSteps = steps;
step = (n2 - n1) / numSteps; step = (n2 - n1) / numSteps;
remainder = modulo = (n2 - n1) % numSteps; remainder = modulo = (n2 - n1) % numSteps;
n = n1 + offsetInt; n = n1 + offsetInt;
@@ -1767,11 +1772,7 @@ struct ClipRegions
return toEdgeTable()->clipToImageAlpha (image, transform, quality); return toEdgeTable()->clipToImageAlpha (image, transform, quality);
} }
void translate (Point<int> delta)
{
clip.offsetAll (delta.x, delta.y);
}
void translate (Point<int> delta) { clip.offsetAll (delta); }
bool clipRegionIntersects (const Rectangle<int>& r) const { return clip.intersects (r); } bool clipRegionIntersects (const Rectangle<int>& r) const { return clip.intersects (r); }
Rectangle<int> getClipBounds() const { return clip.getBounds(); } Rectangle<int> getClipBounds() const { return clip.getBounds(); }
@@ -2399,7 +2400,6 @@ public:
s->image = Image (Image::ARGB, layerBounds.getWidth(), layerBounds.getHeight(), true); s->image = Image (Image::ARGB, layerBounds.getWidth(), layerBounds.getHeight(), true);
s->transparencyLayerAlpha = opacity; s->transparencyLayerAlpha = opacity;
s->transform.moveOriginInDeviceSpace (-layerBounds.getPosition()); s->transform.moveOriginInDeviceSpace (-layerBounds.getPosition());
s->cloneClipIfMultiplyReferenced(); s->cloneClipIfMultiplyReferenced();
s->clip->translate (-layerBounds.getPosition()); s->clip->translate (-layerBounds.getPosition());
} }
@@ -2415,8 +2415,7 @@ public:
const ScopedPointer<LowLevelGraphicsContext> g (image.createLowLevelContext()); const ScopedPointer<LowLevelGraphicsContext> g (image.createLowLevelContext());
g->setOpacity (finishedLayerState.transparencyLayerAlpha); g->setOpacity (finishedLayerState.transparencyLayerAlpha);
g->drawImage (finishedLayerState.image, AffineTransform::translation ((float) layerBounds.getX(),
(float) layerBounds.getY()));
g->drawImage (finishedLayerState.image, AffineTransform::translation (layerBounds.getPosition()));
} }
} }


+ 7
- 8
modules/juce_gui_basics/commands/juce_ApplicationCommandTarget.cpp View File

@@ -63,15 +63,14 @@ bool ApplicationCommandTarget::tryToInvoke (const InvocationInfo& info, const bo
(new CommandMessage (this, info))->post(); (new CommandMessage (this, info))->post();
return true; return true;
} }
else
{
const bool success = perform (info);
jassert (success); // Hmm.. your target claimed that it could perform this command, but failed to do so.
// If it can't do it at the moment for some reason, it should clear the 'isActive' flag
// when it returns the command's info.
return success;
}
if (perform (info))
return true;
// Hmm.. your target claimed that it could perform this command, but failed to do so.
// If it can't do it at the moment for some reason, it should clear the 'isActive' flag
// when it returns the command's info.
jassertfalse;
} }
return false; return false;


+ 7
- 14
modules/juce_gui_basics/mouse/juce_LassoComponent.h View File

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


+ 29
- 23
modules/juce_gui_basics/mouse/juce_SelectedItemSet.h View File

@@ -47,6 +47,7 @@ class SelectedItemSet : public ChangeBroadcaster
public: public:
//============================================================================== //==============================================================================
typedef SelectableItemType ItemType; typedef SelectableItemType ItemType;
typedef Array<SelectableItemType> ItemArray;
typedef PARAMETER_TYPE (SelectableItemType) ParameterType; typedef PARAMETER_TYPE (SelectableItemType) ParameterType;
//============================================================================== //==============================================================================
@@ -56,7 +57,7 @@ public:
} }
/** Creates a set based on an array of items. */ /** Creates a set based on an array of items. */
explicit SelectedItemSet (const Array <SelectableItemType>& items)
explicit SelectedItemSet (const ItemArray& items)
: selectedItems (items) : selectedItems (items)
{ {
} }
@@ -247,30 +248,25 @@ public:
/** Returns the number of currently selected items. /** Returns the number of currently selected items.
@see getSelectedItem @see getSelectedItem
*/ */
int getNumSelected() const noexcept
{
return selectedItems.size();
}
int getNumSelected() const noexcept { return selectedItems.size(); }
/** Returns one of the currently selected items. /** 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 @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. */ /** 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. /** 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 For example, if the item is an object, you might want to call it and tell
it that it's being selected. 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. /** 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 For example, if the item is an object, you might want to call it and tell
it that it's being deselected. 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()
{
sendChangeMessage();
}
/** 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 (const bool synchronous)
{ {
if (synchronous) if (synchronous)
sendSynchronousChangeMessage(); sendSynchronousChangeMessage();
@@ -298,9 +304,9 @@ public:
private: private:
//============================================================================== //==============================================================================
Array <SelectableItemType> selectedItems;
ItemArray selectedItems;
JUCE_LEAK_DETECTOR (SelectedItemSet <SelectableItemType>)
JUCE_LEAK_DETECTOR (SelectedItemSet<SelectableItemType>)
}; };


Loading…
Cancel
Save