diff --git a/modules/juce_gui_basics/components/juce_Component.cpp b/modules/juce_gui_basics/components/juce_Component.cpp index 3f1b39b0f5..945b1a3100 100644 --- a/modules/juce_gui_basics/components/juce_Component.cpp +++ b/modules/juce_gui_basics/components/juce_Component.cpp @@ -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) diff --git a/modules/juce_gui_basics/components/juce_Component.h b/modules/juce_gui_basics/components/juce_Component.h index 188c0bf528..b68c9c3662 100644 --- a/modules/juce_gui_basics/components/juce_Component.h +++ b/modules/juce_gui_basics/components/juce_Component.h @@ -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. diff --git a/modules/juce_gui_basics/drawables/juce_Drawable.h b/modules/juce_gui_basics/drawables/juce_Drawable.h index 95b39b49d6..798302e774 100644 --- a/modules/juce_gui_basics/drawables/juce_Drawable.h +++ b/modules/juce_gui_basics/drawables/juce_Drawable.h @@ -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; diff --git a/modules/juce_gui_basics/positioning/juce_MarkerList.h b/modules/juce_gui_basics/positioning/juce_MarkerList.h index c73f1f5ab9..0fde315bc1 100644 --- a/modules/juce_gui_basics/positioning/juce_MarkerList.h +++ b/modules/juce_gui_basics/positioning/juce_MarkerList.h @@ -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 diff --git a/modules/juce_gui_basics/positioning/juce_RelativeCoordinatePositioner.cpp b/modules/juce_gui_basics/positioning/juce_RelativeCoordinatePositioner.cpp index 9afd38ee78..f8fc10b8da 100644 --- a/modules/juce_gui_basics/positioning/juce_RelativeCoordinatePositioner.cpp +++ b/modules/juce_gui_basics/positioning/juce_RelativeCoordinatePositioner.cpp @@ -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 (&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 (parent)) + { + positioner.registerMarkerListListener (mlh->getMarkers (true)); + positioner.registerMarkerListListener (mlh->getMarkers (false)); + } + ok = false; } }