Browse Source

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

tags/2021-05-28
jules 7 years ago
parent
commit
e6267afaae
5 changed files with 36 additions and 24 deletions
  1. +0
    -6
      modules/juce_gui_basics/components/juce_Component.cpp
  2. +0
    -8
      modules/juce_gui_basics/components/juce_Component.h
  3. +4
    -1
      modules/juce_gui_basics/drawables/juce_Drawable.h
  4. +10
    -0
      modules/juce_gui_basics/positioning/juce_MarkerList.h
  5. +22
    -9
      modules/juce_gui_basics/positioning/juce_RelativeCoordinatePositioner.cpp

+ 0
- 6
modules/juce_gui_basics/components/juce_Component.cpp 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)


+ 0
- 8
modules/juce_gui_basics/components/juce_Component.h 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.


+ 4
- 1
modules/juce_gui_basics/drawables/juce_Drawable.h 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;


+ 10
- 0
modules/juce_gui_basics/positioning/juce_MarkerList.h 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


+ 22
- 9
modules/juce_gui_basics/positioning/juce_RelativeCoordinatePositioner.cpp 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;
}
}


Loading…
Cancel
Save