1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-02-07 04:10:08 +00:00

Fixed a problem with mouse interception in Drawable's base class copy constructor

This commit is contained in:
jules 2017-04-25 09:07:11 +01:00
parent ee3457abb1
commit a4c0968635
2 changed files with 29 additions and 29 deletions

View file

@ -31,6 +31,9 @@ Drawable::Drawable()
Drawable::Drawable (const Drawable& other)
: Component (other.getName())
{
setInterceptsMouseClicks (false, false);
setPaintingIsUnclipped (true);
setComponentID (other.getComponentID());
setTransform (other.getTransform());
}
@ -74,7 +77,7 @@ void Drawable::drawAt (Graphics& g, float x, float y, float opacity) const
draw (g, opacity, AffineTransform::translation (x, y));
}
void Drawable::drawWithin (Graphics& g, const Rectangle<float>& destArea,
void Drawable::drawWithin (Graphics& g, Rectangle<float> destArea,
RectanglePlacement placement, float opacity) const
{
draw (g, opacity, placement.getTransformToFit (getDrawableBounds(), destArea));
@ -96,14 +99,14 @@ void Drawable::parentHierarchyChanged()
setBoundsToEnclose (getDrawableBounds());
}
void Drawable::setBoundsToEnclose (const Rectangle<float>& area)
void Drawable::setBoundsToEnclose (Rectangle<float> area)
{
Drawable* const parent = getParent();
Point<int> parentOrigin;
if (parent != nullptr)
if (auto* parent = getParent())
parentOrigin = parent->originRelativeToComponent;
const Rectangle<int> newBounds (area.getSmallestIntegerContainer() + parentOrigin);
auto newBounds = area.getSmallestIntegerContainer() + parentOrigin;
originRelativeToComponent = parentOrigin - newBounds.getPosition();
setBounds (newBounds);
}
@ -114,7 +117,7 @@ bool Drawable::replaceColour (Colour original, Colour replacement)
bool changed = false;
for (int i = getNumChildComponents(); --i >= 0;)
if (Drawable* d = dynamic_cast<Drawable*> (getChildComponent(i)))
if (auto* d = dynamic_cast<Drawable*> (getChildComponent(i)))
changed = d->replaceColour (original, replacement) || changed;
return changed;
@ -137,17 +140,17 @@ Drawable* Drawable::createFromImageData (const void* data, const size_t numBytes
{
Drawable* result = nullptr;
Image image (ImageFileFormat::loadFrom (data, numBytes));
auto image = ImageFileFormat::loadFrom (data, numBytes);
if (image.isValid())
{
DrawableImage* const di = new DrawableImage();
auto* di = new DrawableImage();
di->setImage (image);
result = di;
}
else
{
const String asString (String::createStringFromData (data, (int) numBytes));
auto asString = String::createStringFromData (data, (int) numBytes);
XmlDocument doc (asString);
ScopedPointer<XmlElement> outer (doc.getDocumentElement (true));
@ -181,17 +184,15 @@ Drawable* Drawable::createFromImageFile (const File& file)
//==============================================================================
template <class DrawableClass>
class DrawableTypeHandler : public ComponentBuilder::TypeHandler
struct DrawableTypeHandler : public ComponentBuilder::TypeHandler
{
public:
DrawableTypeHandler()
: ComponentBuilder::TypeHandler (DrawableClass::valueTreeType)
DrawableTypeHandler() : ComponentBuilder::TypeHandler (DrawableClass::valueTreeType)
{
}
Component* addNewComponentFromState (const ValueTree& state, Component* parent)
{
DrawableClass* const d = new DrawableClass();
auto* d = new DrawableClass();
if (parent != nullptr)
parent->addAndMakeVisible (d);
@ -202,19 +203,20 @@ public:
void updateComponentFromState (Component* component, const ValueTree& state)
{
DrawableClass* const d = dynamic_cast<DrawableClass*> (component);
jassert (d != nullptr);
d->refreshFromValueTree (state, *this->getBuilder());
if (auto* d = dynamic_cast<DrawableClass*> (component))
d->refreshFromValueTree (state, *this->getBuilder());
else
jassertfalse;
}
};
void Drawable::registerDrawableTypeHandlers (ComponentBuilder& builder)
{
builder.registerTypeHandler (new DrawableTypeHandler <DrawablePath>());
builder.registerTypeHandler (new DrawableTypeHandler <DrawableComposite>());
builder.registerTypeHandler (new DrawableTypeHandler <DrawableRectangle>());
builder.registerTypeHandler (new DrawableTypeHandler <DrawableImage>());
builder.registerTypeHandler (new DrawableTypeHandler <DrawableText>());
builder.registerTypeHandler (new DrawableTypeHandler<DrawablePath>());
builder.registerTypeHandler (new DrawableTypeHandler<DrawableComposite>());
builder.registerTypeHandler (new DrawableTypeHandler<DrawableRectangle>());
builder.registerTypeHandler (new DrawableTypeHandler<DrawableImage>());
builder.registerTypeHandler (new DrawableTypeHandler<DrawableText>());
}
Drawable* Drawable::createFromValueTree (const ValueTree& tree, ComponentBuilder::ImageProvider* imageProvider)
@ -224,7 +226,7 @@ Drawable* Drawable::createFromValueTree (const ValueTree& tree, ComponentBuilder
registerDrawableTypeHandlers (builder);
ScopedPointer<Component> comp (builder.createComponent());
Drawable* const d = dynamic_cast<Drawable*> (static_cast<Component*> (comp));
auto* d = dynamic_cast<Drawable*> (static_cast<Component*> (comp));
if (d != nullptr)
comp.release();
@ -233,8 +235,7 @@ Drawable* Drawable::createFromValueTree (const ValueTree& tree, ComponentBuilder
}
//==============================================================================
Drawable::ValueTreeWrapperBase::ValueTreeWrapperBase (const ValueTree& state_)
: state (state_)
Drawable::ValueTreeWrapperBase::ValueTreeWrapperBase (const ValueTree& s) : state (s)
{
}

View file

@ -61,8 +61,7 @@ public:
@see drawWithin
*/
void draw (Graphics& g, float opacity,
const AffineTransform& transform = AffineTransform()) const;
void draw (Graphics& g, float opacity, const AffineTransform& transform = {}) const;
/** Renders the Drawable at a given offset within the Graphics context.
@ -96,7 +95,7 @@ public:
@param opacity the opacity to use, in the range 0 to 1.0
*/
void drawWithin (Graphics& g,
const Rectangle<float>& destArea,
Rectangle<float> destArea,
RectanglePlacement placement,
float opacity) const;
@ -211,7 +210,7 @@ protected:
/** @internal */
void parentHierarchyChanged() override;
/** @internal */
void setBoundsToEnclose (const Rectangle<float>&);
void setBoundsToEnclose (Rectangle<float>);
Point<int> originRelativeToComponent;