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

Added a base class MarkerList::MarkerListHolder, and used it to remove the getMarkers() method from Component.

This commit is contained in:
jules 2017-12-22 13:05:11 +00:00
parent a253168a25
commit e6267afaae
5 changed files with 36 additions and 24 deletions

View file

@ -2139,12 +2139,6 @@ void Component::copyAllExplicitColoursTo (Component& target) const
target.colourChanged();
}
//==============================================================================
MarkerList* Component::getMarkers (bool /*xAxis*/)
{
return nullptr;
}
//==============================================================================
Component::Positioner::Positioner (Component& c) noexcept
: component (c)

View file

@ -2105,14 +2105,6 @@ public:
*/
virtual void colourChanged();
//==============================================================================
/** Components can implement this method to provide a MarkerList.
The default implementation of this method returns nullptr, but you can override
it to return a pointer to the component's marker list. If xAxis is true, it should
return the X marker list; if false, it should return the Y markers.
*/
virtual MarkerList* getMarkers (bool xAxis);
//==============================================================================
/** Returns the underlying native window handle for this component.

View file

@ -33,7 +33,8 @@ namespace juce
@see DrawableComposite, DrawableImage, DrawablePath, DrawableText
*/
class JUCE_API Drawable : public Component
class JUCE_API Drawable : public Component,
public MarkerList::MarkerListHolder
{
protected:
//==============================================================================
@ -225,6 +226,8 @@ public:
*/
static void registerDrawableTypeHandlers (ComponentBuilder& componentBuilder);
MarkerList* getMarkers (bool) override { return nullptr; }
protected:
//==============================================================================
friend class DrawableComposite;

View file

@ -146,6 +146,16 @@ public:
/** Synchronously calls markersChanged() on all the registered listeners. */
void markersHaveChanged();
//==============================================================================
/** A base class for objects that want to provide a MarkerList. */
struct MarkerListHolder
{
virtual ~MarkerListHolder() {}
/** Objects can implement this method to provide a MarkerList. */
virtual MarkerList* getMarkers (bool xAxis) = 0;
};
//==============================================================================
/** Forms a wrapper around a ValueTree that can be used for storing a MarkerList. */
class ValueTreeWrapper

View file

@ -73,19 +73,28 @@ struct MarkerListScope : public Expression::Scope
static const MarkerList::Marker* findMarker (Component& component, const String& name, MarkerList*& list)
{
const MarkerList::Marker* marker = nullptr;
list = component.getMarkers (true);
if (list != nullptr)
marker = list->getMarker (name);
auto* mlh = dynamic_cast<MarkerList::MarkerListHolder*> (&component);
if (marker == nullptr)
if (mlh != nullptr)
{
list = component.getMarkers (false);
list = mlh->getMarkers (true);
if (list != nullptr)
marker = list->getMarker (name);
}
if (marker == nullptr)
{
if (mlh != nullptr)
{
list = mlh->getMarkers (false);
if (list != nullptr)
marker = list->getMarker (name);
}
}
return marker;
}
@ -117,7 +126,7 @@ Expression RelativeCoordinatePositionerBase::ComponentScope::getSymbolValue (con
{
MarkerList* list;
if (const MarkerList::Marker* const marker = MarkerListScope::findMarker (*parent, symbol, list))
if (auto* marker = MarkerListScope::findMarker (*parent, symbol, list))
{
MarkerListScope scope (*parent);
return Expression (marker->position.getExpression().evaluate (scope));
@ -175,7 +184,7 @@ public:
break;
default:
if (Component* const parent = component.getParentComponent())
if (auto* parent = component.getParentComponent())
{
MarkerList* list;
@ -186,8 +195,12 @@ public:
else
{
// The marker we want doesn't exist, so watch all lists in case they change and the marker appears later..
positioner.registerMarkerListListener (parent->getMarkers (true));
positioner.registerMarkerListListener (parent->getMarkers (false));
if (auto* mlh = dynamic_cast<MarkerList::MarkerListHolder*> (parent))
{
positioner.registerMarkerListListener (mlh->getMarkers (true));
positioner.registerMarkerListListener (mlh->getMarkers (false));
}
ok = false;
}
}