Browse Source

Minor clean-ups and documentation fixes.

tags/2021-05-28
jules 12 years ago
parent
commit
5d35a31f2e
7 changed files with 152 additions and 152 deletions
  1. +21
    -13
      modules/juce_core/containers/juce_Variant.cpp
  2. +4
    -7
      modules/juce_data_structures/values/juce_ValueTree.cpp
  3. +2
    -2
      modules/juce_graphics/fonts/juce_TextLayout.cpp
  4. +101
    -106
      modules/juce_gui_basics/drawables/juce_SVGParser.cpp
  5. +2
    -4
      modules/juce_gui_basics/layout/juce_ScrollBar.h
  6. +18
    -18
      modules/juce_gui_basics/widgets/juce_TableListBox.cpp
  7. +4
    -2
      modules/juce_gui_basics/widgets/juce_TreeView.cpp

+ 21
- 13
modules/juce_core/containers/juce_Variant.cpp View File

@@ -454,8 +454,10 @@ bool operator!= (const var& v1, const char* const v2) { return v1.toString
//============================================================================== //==============================================================================
var var::operator[] (const Identifier& propertyName) const var var::operator[] (const Identifier& propertyName) const
{ {
DynamicObject* const o = getDynamicObject();
return o != nullptr ? o->getProperty (propertyName) : var::null;
if (DynamicObject* const o = getDynamicObject())
return o->getProperty (propertyName);
return var::null;
} }
var var::operator[] (const char* const propertyName) const var var::operator[] (const char* const propertyName) const
@@ -465,14 +467,18 @@ var var::operator[] (const char* const propertyName) const
var var::getProperty (const Identifier& propertyName, const var& defaultReturnValue) const var var::getProperty (const Identifier& propertyName, const var& defaultReturnValue) const
{ {
DynamicObject* const o = getDynamicObject();
return o != nullptr ? o->getProperties().getWithDefault (propertyName, defaultReturnValue) : defaultReturnValue;
if (DynamicObject* const o = getDynamicObject())
return o->getProperties().getWithDefault (propertyName, defaultReturnValue);
return defaultReturnValue;
} }
var var::invoke (const Identifier& method, const var* arguments, int numArguments) const var var::invoke (const Identifier& method, const var* arguments, int numArguments) const
{ {
DynamicObject* const o = getDynamicObject();
return o != nullptr ? o->invokeMethod (method, arguments, numArguments) : var::null;
if (DynamicObject* const o = getDynamicObject())
return o->invokeMethod (method, arguments, numArguments);
return var::null;
} }
var var::invokeMethod (DynamicObject* const target, const var* const arguments, const int numArguments) const var var::invokeMethod (DynamicObject* const target, const var* const arguments, const int numArguments) const
@@ -522,8 +528,10 @@ var var::call (const Identifier& method, const var& arg1, const var& arg2, const
//============================================================================== //==============================================================================
int var::size() const int var::size() const
{ {
const Array<var>* const array = getArray();
return array != nullptr ? array->size() : 0;
if (const Array<var>* const array = getArray())
return array->size();
return 0;
} }
const var& var::operator[] (int arrayIndex) const const var& var::operator[] (int arrayIndex) const
@@ -574,9 +582,7 @@ void var::append (const var& n)
void var::remove (const int index) void var::remove (const int index)
{ {
Array<var>* const array = getArray();
if (array != nullptr)
if (Array<var>* const array = getArray())
array->remove (index); array->remove (index);
} }
@@ -592,8 +598,10 @@ void var::resize (const int numArrayElementsWanted)
int var::indexOf (const var& n) const int var::indexOf (const var& n) const
{ {
const Array<var>* const array = getArray();
return array != nullptr ? array->indexOf (n) : -1;
if (const Array<var>* const array = getArray())
return array->indexOf (n);
return -1;
} }
//============================================================================== //==============================================================================


+ 4
- 7
modules/juce_data_structures/values/juce_ValueTree.cpp View File

@@ -482,13 +482,10 @@ public:
{ {
if (! (isAddingNewProperty || isDeletingProperty)) if (! (isAddingNewProperty || isDeletingProperty))
{ {
SetPropertyAction* const next = dynamic_cast <SetPropertyAction*> (nextAction);
if (next != nullptr && next->target == target && next->name == name
&& ! (next->isAddingNewProperty || next->isDeletingProperty))
{
return new SetPropertyAction (target, name, next->newValue, oldValue, false, false);
}
if (SetPropertyAction* const next = dynamic_cast <SetPropertyAction*> (nextAction))
if (next->target == target && next->name == name
&& ! (next->isAddingNewProperty || next->isDeletingProperty))
return new SetPropertyAction (target, name, next->newValue, oldValue, false, false);
} }
return nullptr; return nullptr;


+ 2
- 2
modules/juce_graphics/fonts/juce_TextLayout.cpp View File

@@ -521,8 +521,8 @@ namespace TextLayoutHelpers
if (attr.range.contains (i)) if (attr.range.contains (i))
{ {
if (attr.getFont() != nullptr) newFontAndColour.font = attr.getFont();
if (attr.getColour() != nullptr) newFontAndColour.colour = *attr.getColour();
if (const Font* f = attr.getFont()) newFontAndColour.font = f;
if (const Colour* c = attr.getColour()) newFontAndColour.colour = *c;
} }
} }


+ 101
- 106
modules/juce_gui_basics/drawables/juce_SVGParser.cpp View File

@@ -146,9 +146,7 @@ private:
DrawableComposite* parseSwitch (const XmlElement& xml) DrawableComposite* parseSwitch (const XmlElement& xml)
{ {
const XmlElement* const group = xml.getChildByName ("g");
if (group != nullptr)
if (const XmlElement* const group = xml.getChildByName ("g"))
return parseGroupElement (*group); return parseGroupElement (*group);
return nullptr; return nullptr;
@@ -572,142 +570,141 @@ private:
void addGradientStopsIn (ColourGradient& cg, const XmlElement* const fillXml) const void addGradientStopsIn (ColourGradient& cg, const XmlElement* const fillXml) const
{ {
if (fillXml == 0)
return;
forEachXmlChildElementWithTagName (*fillXml, e, "stop")
if (fillXml != nullptr)
{ {
int index = 0;
Colour col (parseColour (getStyleAttribute (e, "stop-color"), index, Colours::black));
forEachXmlChildElementWithTagName (*fillXml, e, "stop")
{
int index = 0;
Colour col (parseColour (getStyleAttribute (e, "stop-color"), index, Colours::black));
const String opacity (getStyleAttribute (e, "stop-opacity", "1"));
col = col.withMultipliedAlpha (jlimit (0.0f, 1.0f, opacity.getFloatValue()));
const String opacity (getStyleAttribute (e, "stop-opacity", "1"));
col = col.withMultipliedAlpha (jlimit (0.0f, 1.0f, opacity.getFloatValue()));
double offset = e->getDoubleAttribute ("offset");
double offset = e->getDoubleAttribute ("offset");
if (e->getStringAttribute ("offset").containsChar ('%'))
offset *= 0.01;
if (e->getStringAttribute ("offset").containsChar ('%'))
offset *= 0.01;
cg.addColour (jlimit (0.0, 1.0, offset), col);
cg.addColour (jlimit (0.0, 1.0, offset), col);
}
} }
} }
FillType getPathFillType (const Path& path,
const String& fill,
const String& fillOpacity,
const String& overallOpacity,
const Colour& defaultColour) const
FillType getGradientFillType (const XmlElement* fillXml,
const Path& path,
const float opacity) const
{ {
float opacity = 1.0f;
ColourGradient gradient;
if (overallOpacity.isNotEmpty())
opacity = jlimit (0.0f, 1.0f, overallOpacity.getFloatValue());
addGradientStopsIn (gradient, findLinkedElement (fillXml));
addGradientStopsIn (gradient, fillXml);
if (fillOpacity.isNotEmpty())
opacity *= (jlimit (0.0f, 1.0f, fillOpacity.getFloatValue()));
if (fill.startsWithIgnoreCase ("url"))
if (gradient.getNumColours() > 0)
{ {
const String id (fill.fromFirstOccurrenceOf ("#", false, false)
.upToLastOccurrenceOf (")", false, false).trim());
gradient.addColour (0.0, gradient.getColour (0));
gradient.addColour (1.0, gradient.getColour (gradient.getNumColours() - 1));
}
else
{
gradient.addColour (0.0, Colours::black);
gradient.addColour (1.0, Colours::black);
}
const XmlElement* const fillXml = findElementForId (topLevelXml, id);
if (opacity < 1.0f)
gradient.multiplyOpacity (opacity);
if (fillXml != nullptr
&& (fillXml->hasTagName ("linearGradient")
|| fillXml->hasTagName ("radialGradient")))
{
const XmlElement* inheritedFrom = findLinkedElement (fillXml);
jassert (gradient.getNumColours() > 0);
ColourGradient gradient;
gradient.isRadial = fillXml->hasTagName ("radialGradient");
addGradientStopsIn (gradient, inheritedFrom);
addGradientStopsIn (gradient, fillXml);
float gradientWidth = viewBoxW;
float gradientHeight = viewBoxH;
float dx = 0.0f;
float dy = 0.0f;
if (gradient.getNumColours() > 0)
{
gradient.addColour (0.0, gradient.getColour (0));
gradient.addColour (1.0, gradient.getColour (gradient.getNumColours() - 1));
}
else
{
gradient.addColour (0.0, Colours::black);
gradient.addColour (1.0, Colours::black);
}
const bool userSpace = fillXml->getStringAttribute ("gradientUnits").equalsIgnoreCase ("userSpaceOnUse");
if (overallOpacity.isNotEmpty())
gradient.multiplyOpacity (overallOpacity.getFloatValue());
if (! userSpace)
{
const Rectangle<float> bounds (path.getBounds());
dx = bounds.getX();
dy = bounds.getY();
gradientWidth = bounds.getWidth();
gradientHeight = bounds.getHeight();
}
jassert (gradient.getNumColours() > 0);
if (gradient.isRadial)
{
if (userSpace)
gradient.point1.setXY (dx + getCoordLength (fillXml->getStringAttribute ("cx", "50%"), gradientWidth),
dy + getCoordLength (fillXml->getStringAttribute ("cy", "50%"), gradientHeight));
else
gradient.point1.setXY (dx + gradientWidth * getCoordLength (fillXml->getStringAttribute ("cx", "50%"), 1.0f),
dy + gradientHeight * getCoordLength (fillXml->getStringAttribute ("cy", "50%"), 1.0f));
gradient.isRadial = fillXml->hasTagName ("radialGradient");
const float radius = getCoordLength (fillXml->getStringAttribute ("r", "50%"), gradientWidth);
gradient.point2 = gradient.point1 + Point<float> (radius, 0.0f);
float gradientWidth = viewBoxW;
float gradientHeight = viewBoxH;
float dx = 0.0f;
float dy = 0.0f;
//xxx (the fx, fy focal point isn't handled properly here..)
}
else
{
if (userSpace)
{
gradient.point1.setXY (dx + getCoordLength (fillXml->getStringAttribute ("x1", "0%"), gradientWidth),
dy + getCoordLength (fillXml->getStringAttribute ("y1", "0%"), gradientHeight));
const bool userSpace = fillXml->getStringAttribute ("gradientUnits").equalsIgnoreCase ("userSpaceOnUse");
gradient.point2.setXY (dx + getCoordLength (fillXml->getStringAttribute ("x2", "100%"), gradientWidth),
dy + getCoordLength (fillXml->getStringAttribute ("y2", "0%"), gradientHeight));
}
else
{
gradient.point1.setXY (dx + gradientWidth * getCoordLength (fillXml->getStringAttribute ("x1", "0%"), 1.0f),
dy + gradientHeight * getCoordLength (fillXml->getStringAttribute ("y1", "0%"), 1.0f));
if (! userSpace)
{
const Rectangle<float> bounds (path.getBounds());
dx = bounds.getX();
dy = bounds.getY();
gradientWidth = bounds.getWidth();
gradientHeight = bounds.getHeight();
}
gradient.point2.setXY (dx + gradientWidth * getCoordLength (fillXml->getStringAttribute ("x2", "100%"), 1.0f),
dy + gradientHeight * getCoordLength (fillXml->getStringAttribute ("y2", "0%"), 1.0f));
}
if (gradient.isRadial)
{
if (userSpace)
gradient.point1.setXY (dx + getCoordLength (fillXml->getStringAttribute ("cx", "50%"), gradientWidth),
dy + getCoordLength (fillXml->getStringAttribute ("cy", "50%"), gradientHeight));
else
gradient.point1.setXY (dx + gradientWidth * getCoordLength (fillXml->getStringAttribute ("cx", "50%"), 1.0f),
dy + gradientHeight * getCoordLength (fillXml->getStringAttribute ("cy", "50%"), 1.0f));
if (gradient.point1 == gradient.point2)
return Colour (gradient.getColour (gradient.getNumColours() - 1));
}
const float radius = getCoordLength (fillXml->getStringAttribute ("r", "50%"), gradientWidth);
gradient.point2 = gradient.point1 + Point<float> (radius, 0.0f);
FillType type (gradient);
type.transform = parseTransform (fillXml->getStringAttribute ("gradientTransform"))
.followedBy (transform);
return type;
}
//xxx (the fx, fy focal point isn't handled properly here..)
}
else
{
if (userSpace)
{
gradient.point1.setXY (dx + getCoordLength (fillXml->getStringAttribute ("x1", "0%"), gradientWidth),
dy + getCoordLength (fillXml->getStringAttribute ("y1", "0%"), gradientHeight));
FillType getPathFillType (const Path& path,
const String& fill,
const String& fillOpacity,
const String& overallOpacity,
const Colour& defaultColour) const
{
float opacity = 1.0f;
gradient.point2.setXY (dx + getCoordLength (fillXml->getStringAttribute ("x2", "100%"), gradientWidth),
dy + getCoordLength (fillXml->getStringAttribute ("y2", "0%"), gradientHeight));
}
else
{
gradient.point1.setXY (dx + gradientWidth * getCoordLength (fillXml->getStringAttribute ("x1", "0%"), 1.0f),
dy + gradientHeight * getCoordLength (fillXml->getStringAttribute ("y1", "0%"), 1.0f));
if (overallOpacity.isNotEmpty())
opacity = jlimit (0.0f, 1.0f, overallOpacity.getFloatValue());
gradient.point2.setXY (dx + gradientWidth * getCoordLength (fillXml->getStringAttribute ("x2", "100%"), 1.0f),
dy + gradientHeight * getCoordLength (fillXml->getStringAttribute ("y2", "0%"), 1.0f));
}
if (fillOpacity.isNotEmpty())
opacity *= (jlimit (0.0f, 1.0f, fillOpacity.getFloatValue()));
if (gradient.point1 == gradient.point2)
return Colour (gradient.getColour (gradient.getNumColours() - 1));
}
if (fill.startsWithIgnoreCase ("url"))
{
const String id (fill.fromFirstOccurrenceOf ("#", false, false)
.upToLastOccurrenceOf (")", false, false).trim());
FillType type (gradient);
type.transform = parseTransform (fillXml->getStringAttribute ("gradientTransform"))
.followedBy (transform);
return type;
}
if (const XmlElement* const fillXml = findElementForId (topLevelXml, id))
if (fillXml->hasTagName ("linearGradient") || fillXml->hasTagName ("radialGradient"))
return getGradientFillType (fillXml, path, opacity);
} }
if (fill.equalsIgnoreCase ("none")) if (fill.equalsIgnoreCase ("none"))
return Colours::transparentBlack; return Colours::transparentBlack;
int i = 0; int i = 0;
const Colour colour (parseColour (fill, i, defaultColour));
return colour.withMultipliedAlpha (opacity);
return parseColour (fill, i, defaultColour).withMultipliedAlpha (opacity);
} }
PathStrokeType getStrokeFor (const XmlElement* const xml) const PathStrokeType getStrokeFor (const XmlElement* const xml) const
@@ -1216,9 +1213,7 @@ private:
if (e->compareAttribute ("id", id)) if (e->compareAttribute ("id", id))
return e; return e;
const XmlElement* const found = findElementForId (e, id);
if (found != nullptr)
if (const XmlElement* const found = findElementForId (e, id))
return found; return found;
} }


+ 2
- 4
modules/juce_gui_basics/layout/juce_ScrollBar.h View File

@@ -153,16 +153,14 @@ public:
This sets both the position and size of the thumb - to just set the position without This sets both the position and size of the thumb - to just set the position without
changing the size, you can use setCurrentRangeStart(). changing the size, you can use setCurrentRangeStart().
If this method call actually changes the scrollbar's position, it will trigger an
asynchronous call to ScrollBar::Listener::scrollBarMoved() for all the listeners that
are registered.
@param newStart the top (or left) of the thumb, in the range @param newStart the top (or left) of the thumb, in the range
getMinimumRangeLimit() <= newStart <= getMaximumRangeLimit(). If the getMinimumRangeLimit() <= newStart <= getMaximumRangeLimit(). If the
value is beyond these limits, it will be clipped. value is beyond these limits, it will be clipped.
@param newSize the size of the thumb, such that @param newSize the size of the thumb, such that
getMinimumRangeLimit() <= newStart + newSize <= getMaximumRangeLimit(). If the getMinimumRangeLimit() <= newStart + newSize <= getMaximumRangeLimit(). If the
size is beyond these limits, it will be clipped. size is beyond these limits, it will be clipped.
@param notification specifies if and how a callback should be made to any listeners
if the range actually changes
@see setCurrentRangeStart, getCurrentRangeStart, getCurrentRangeSize @see setCurrentRangeStart, getCurrentRangeStart, getCurrentRangeSize
*/ */
void setCurrentRange (double newStart, double newSize, void setCurrentRange (double newStart, double newSize,


+ 18
- 18
modules/juce_gui_basics/widgets/juce_TableListBox.cpp View File

@@ -132,8 +132,9 @@ public:
const int columnId = owner.getHeader().getColumnIdAtX (e.x); const int columnId = owner.getHeader().getColumnIdAtX (e.x);
if (columnId != 0 && owner.getModel() != nullptr)
owner.getModel()->cellClicked (row, columnId, e);
if (columnId != 0)
if (TableListBoxModel* model = owner.getModel())
model->cellClicked (row, columnId, e);
} }
else else
{ {
@@ -169,8 +170,9 @@ public:
const int columnId = owner.getHeader().getColumnIdAtX (e.x); const int columnId = owner.getHeader().getColumnIdAtX (e.x);
if (columnId != 0 && owner.getModel() != nullptr)
owner.getModel()->cellClicked (row, columnId, e);
if (columnId != 0)
if (TableListBoxModel* model = owner.getModel())
model->cellClicked (row, columnId, e);
} }
} }
@@ -178,16 +180,18 @@ public:
{ {
const int columnId = owner.getHeader().getColumnIdAtX (e.x); const int columnId = owner.getHeader().getColumnIdAtX (e.x);
if (columnId != 0 && owner.getModel() != nullptr)
owner.getModel()->cellDoubleClicked (row, columnId, e);
if (columnId != 0)
if (TableListBoxModel* model = owner.getModel())
model->cellDoubleClicked (row, columnId, e);
} }
String getTooltip() String getTooltip()
{ {
const int columnId = owner.getHeader().getColumnIdAtX (getMouseXYRelative().getX()); const int columnId = owner.getHeader().getColumnIdAtX (getMouseXYRelative().getX());
if (columnId != 0 && owner.getModel() != nullptr)
return owner.getModel()->getCellTooltip (row, columnId);
if (columnId != 0)
if (TableListBoxModel* model = owner.getModel())
return model->getCellTooltip (row, columnId);
return String::empty; return String::empty;
} }
@@ -334,15 +338,15 @@ Rectangle<int> TableListBox::getCellPosition (const int columnId, const int rowN
Component* TableListBox::getCellComponent (int columnId, int rowNumber) const Component* TableListBox::getCellComponent (int columnId, int rowNumber) const
{ {
RowComp* const rowComp = dynamic_cast <RowComp*> (getComponentForRowNumber (rowNumber));
return rowComp != nullptr ? rowComp->findChildComponentForColumn (columnId) : 0;
if (RowComp* const rowComp = dynamic_cast <RowComp*> (getComponentForRowNumber (rowNumber)))
return rowComp->findChildComponentForColumn (columnId);
return nullptr;
} }
void TableListBox::scrollToEnsureColumnIsOnscreen (const int columnId) void TableListBox::scrollToEnsureColumnIsOnscreen (const int columnId)
{ {
ScrollBar* const scrollbar = getHorizontalScrollBar();
if (scrollbar != nullptr)
if (ScrollBar* const scrollbar = getHorizontalScrollBar())
{ {
const Rectangle<int> pos (header->getColumnPosition (header->getIndexOfColumnId (columnId, true))); const Rectangle<int> pos (header->getColumnPosition (header->getIndexOfColumnId (columnId, true)));
@@ -447,12 +451,8 @@ void TableListBox::updateColumnComponents() const
const int firstRow = getRowContainingPosition (0, 0); const int firstRow = getRowContainingPosition (0, 0);
for (int i = firstRow + getNumRowsOnScreen() + 2; --i >= firstRow;) for (int i = firstRow + getNumRowsOnScreen() + 2; --i >= firstRow;)
{
RowComp* const rowComp = dynamic_cast <RowComp*> (getComponentForRowNumber (i));
if (rowComp != nullptr)
if (RowComp* const rowComp = dynamic_cast <RowComp*> (getComponentForRowNumber (i)))
rowComp->resized(); rowComp->resized();
}
} }
//============================================================================== //==============================================================================


+ 4
- 2
modules/juce_gui_basics/widgets/juce_TreeView.cpp View File

@@ -363,9 +363,11 @@ private:
static bool isMouseDraggingInChildCompOf (Component* const comp) static bool isMouseDraggingInChildCompOf (Component* const comp)
{ {
for (int i = Desktop::getInstance().getNumMouseSources(); --i >= 0;)
Desktop& desktop = Desktop::getInstance();
for (int i = desktop.getNumMouseSources(); --i >= 0;)
{ {
MouseInputSource* const source = Desktop::getInstance().getMouseSource(i);
MouseInputSource* const source = desktop.getMouseSource(i);
if (source->isDragging()) if (source->isDragging())
if (Component* const underMouse = source->getComponentUnderMouse()) if (Component* const underMouse = source->getComponentUnderMouse())


Loading…
Cancel
Save