From 640042dc64bc3c79208a2eb3ae68f4a791006f0c Mon Sep 17 00:00:00 2001 From: Julian Storer Date: Fri, 4 Jun 2010 12:34:32 +0100 Subject: [PATCH] Minor posix tweaks. Added a tag value to images. Internal changes to Drawables. --- juce_amalgamated.cpp | 107 +++++++++++++----- juce_amalgamated.h | 62 +++++++--- src/core/juce_StandardHeader.h | 2 +- src/gui/graphics/drawables/juce_Drawable.cpp | 32 ++++-- src/gui/graphics/drawables/juce_Drawable.h | 6 +- .../graphics/drawables/juce_DrawableImage.cpp | 18 +++ .../graphics/drawables/juce_DrawableImage.h | 3 + .../graphics/drawables/juce_DrawablePath.cpp | 35 +++--- .../graphics/drawables/juce_DrawablePath.h | 14 ++- src/gui/graphics/imaging/juce_Image.cpp | 10 ++ src/gui/graphics/imaging/juce_Image.h | 42 ++++++- src/native/linux/juce_linux_Threads.cpp | 12 +- 12 files changed, 252 insertions(+), 91 deletions(-) diff --git a/juce_amalgamated.cpp b/juce_amalgamated.cpp index e3ead3d4cd..62bd8cda28 100644 --- a/juce_amalgamated.cpp +++ b/juce_amalgamated.cpp @@ -83856,6 +83856,8 @@ const Identifier Drawable::ValueTreeWrapperBase::gradientPoint2 ("point2"); const Identifier Drawable::ValueTreeWrapperBase::colour ("colour"); const Identifier Drawable::ValueTreeWrapperBase::radial ("radial"); const Identifier Drawable::ValueTreeWrapperBase::colours ("colours"); +const Identifier Drawable::ValueTreeWrapperBase::imageId ("imageId"); +const Identifier Drawable::ValueTreeWrapperBase::imageOpacity ("imageOpacity"); Drawable::ValueTreeWrapperBase::ValueTreeWrapperBase (const ValueTree& state_) : state (state_) @@ -83871,7 +83873,7 @@ const String Drawable::ValueTreeWrapperBase::getID() const return state [idProperty]; } -void Drawable::ValueTreeWrapperBase::setID (const String& newID, UndoManager* undoManager) +void Drawable::ValueTreeWrapperBase::setID (const String& newID, UndoManager* const undoManager) { if (newID.isEmpty()) state.removeProperty (idProperty, undoManager); @@ -83879,8 +83881,8 @@ void Drawable::ValueTreeWrapperBase::setID (const String& newID, UndoManager* un state.setProperty (idProperty, newID, undoManager); } -const FillType Drawable::ValueTreeWrapperBase::readFillType (const ValueTree& v, RelativePoint* gp1, RelativePoint* gp2, - RelativeCoordinate::NamedCoordinateFinder* nameFinder) +const FillType Drawable::ValueTreeWrapperBase::readFillType (const ValueTree& v, RelativePoint* const gp1, RelativePoint* const gp2, + RelativeCoordinate::NamedCoordinateFinder* const nameFinder, ImageProvider* imageProvider) { const String newType (v[type].toString()); @@ -83916,7 +83918,13 @@ const FillType Drawable::ValueTreeWrapperBase::readFillType (const ValueTree& v, } else if (newType == "image") { - jassertfalse; //xxx todo + Image im; + if (imageProvider != 0) + im = imageProvider->getImageForIdentifier (v[imageId]); + + FillType f (im, AffineTransform::identity); + f.setOpacity ((float) v.getProperty (imageOpacity, 1.0f)); + return f; } jassertfalse; @@ -83924,8 +83932,8 @@ const FillType Drawable::ValueTreeWrapperBase::readFillType (const ValueTree& v, } void Drawable::ValueTreeWrapperBase::writeFillType (ValueTree& v, const FillType& fillType, - const RelativePoint* gp1, const RelativePoint* gp2, - UndoManager* const undoManager) + const RelativePoint* const gp1, const RelativePoint* const gp2, + ImageProvider* imageProvider, UndoManager* const undoManager) { if (fillType.isColour()) { @@ -83941,8 +83949,8 @@ void Drawable::ValueTreeWrapperBase::writeFillType (ValueTree& v, const FillType String s; for (int i = 0; i < fillType.gradient->getNumColours(); ++i) - s << " " << fillType.gradient->getColourPosition (i) - << " " << String::toHexString ((int) fillType.gradient->getColour(i).getARGB()); + s << ' ' << fillType.gradient->getColourPosition (i) + << ' ' << String::toHexString ((int) fillType.gradient->getColour(i).getARGB()); v.setProperty (colours, s.trimStart(), undoManager); } @@ -83950,7 +83958,13 @@ void Drawable::ValueTreeWrapperBase::writeFillType (ValueTree& v, const FillType { v.setProperty (type, "image", undoManager); - jassertfalse; //xxx todo + if (imageProvider != 0) + v.setProperty (imageId, imageProvider->getIdentifierForImage (fillType.image), undoManager); + + if (fillType.getOpacity() < 1.0f) + v.setProperty (imageOpacity, fillType.getOpacity(), undoManager); + else + v.removeProperty (imageOpacity, undoManager); } else { @@ -84759,6 +84773,11 @@ const var DrawableImage::ValueTreeWrapper::getImageIdentifier() const return state [image]; } +Value DrawableImage::ValueTreeWrapper::getImageIdentifierValue (UndoManager* undoManager) +{ + return state.getPropertyAsValue (image, undoManager); +} + void DrawableImage::ValueTreeWrapper::setImageIdentifier (const var& newIdentifier, UndoManager* undoManager) { state.setProperty (image, newIdentifier, undoManager); @@ -84769,6 +84788,14 @@ float DrawableImage::ValueTreeWrapper::getOpacity() const return (float) state.getProperty (opacity, 1.0); } +Value DrawableImage::ValueTreeWrapper::getOpacityValue (UndoManager* undoManager) +{ + if (! state.hasProperty (opacity)) + state.setProperty (opacity, 1.0, undoManager); + + return state.getPropertyAsValue (opacity, undoManager); +} + void DrawableImage::ValueTreeWrapper::setOpacity (float newOpacity, UndoManager* undoManager) { state.setProperty (opacity, newOpacity, undoManager); @@ -84787,6 +84814,11 @@ void DrawableImage::ValueTreeWrapper::setOverlayColour (const Colour& newColour, state.setProperty (overlay, String::toHexString ((int) newColour.getARGB()), undoManager); } +Value DrawableImage::ValueTreeWrapper::getOverlayColourValue (UndoManager* undoManager) +{ + return state.getPropertyAsValue (overlay, undoManager); +} + const RelativePoint DrawableImage::ValueTreeWrapper::getTargetPositionForTopLeft() const { const String pos (state [topLeft].toString()); @@ -85065,7 +85097,7 @@ ValueTree DrawablePath::ValueTreeWrapper::getMainFillState() if (v.isValid()) return v; - setMainFill (Colours::black, 0, 0, 0); + setMainFill (Colours::black, 0, 0, 0, 0); return getMainFillState(); } @@ -85075,32 +85107,34 @@ ValueTree DrawablePath::ValueTreeWrapper::getStrokeFillState() if (v.isValid()) return v; - setStrokeFill (Colours::black, 0, 0, 0); + setStrokeFill (Colours::black, 0, 0, 0, 0); return getStrokeFillState(); } -const FillType DrawablePath::ValueTreeWrapper::getMainFill (RelativeCoordinate::NamedCoordinateFinder* nameFinder) const +const FillType DrawablePath::ValueTreeWrapper::getMainFill (RelativeCoordinate::NamedCoordinateFinder* nameFinder, + ImageProvider* imageProvider) const { - return readFillType (state.getChildWithName (fill), 0, 0, nameFinder); + return readFillType (state.getChildWithName (fill), 0, 0, nameFinder, imageProvider); } void DrawablePath::ValueTreeWrapper::setMainFill (const FillType& newFill, const RelativePoint* gp1, - const RelativePoint* gp2, UndoManager* undoManager) + const RelativePoint* gp2, ImageProvider* imageProvider, UndoManager* undoManager) { ValueTree v (state.getOrCreateChildWithName (fill, undoManager)); - writeFillType (v, newFill, gp1, gp2, undoManager); + writeFillType (v, newFill, gp1, gp2, imageProvider, undoManager); } -const FillType DrawablePath::ValueTreeWrapper::getStrokeFill (RelativeCoordinate::NamedCoordinateFinder* nameFinder) const +const FillType DrawablePath::ValueTreeWrapper::getStrokeFill (RelativeCoordinate::NamedCoordinateFinder* nameFinder, + ImageProvider* imageProvider) const { - return readFillType (state.getChildWithName (stroke), 0, 0, nameFinder); + return readFillType (state.getChildWithName (stroke), 0, 0, nameFinder, imageProvider); } void DrawablePath::ValueTreeWrapper::setStrokeFill (const FillType& newFill, const RelativePoint* gp1, - const RelativePoint* gp2, UndoManager* undoManager) + const RelativePoint* gp2, ImageProvider* imageProvider, UndoManager* undoManager) { ValueTree v (state.getOrCreateChildWithName (stroke, undoManager)); - writeFillType (v, newFill, gp1, gp2, undoManager); + writeFillType (v, newFill, gp1, gp2, imageProvider, undoManager); } const PathStrokeType DrawablePath::ValueTreeWrapper::getStrokeType() const @@ -85193,14 +85227,14 @@ const RelativePoint DrawablePath::ValueTreeWrapper::Element::getEndPoint() const return RelativePoint(); } -const Rectangle DrawablePath::refreshFromValueTree (const ValueTree& tree, ImageProvider*) +const Rectangle DrawablePath::refreshFromValueTree (const ValueTree& tree, ImageProvider* imageProvider) { Rectangle damageRect; ValueTreeWrapper v (tree); setName (v.getID()); bool needsRedraw = false; - const FillType newFill (v.getMainFill (parent)); + const FillType newFill (v.getMainFill (parent, imageProvider)); if (mainFill != newFill) { @@ -85208,7 +85242,7 @@ const Rectangle DrawablePath::refreshFromValueTree (const ValueTree& tree mainFill = newFill; } - const FillType newStrokeFill (v.getStrokeFill (parent)); + const FillType newStrokeFill (v.getStrokeFill (parent, imageProvider)); if (strokeFill != newStrokeFill) { @@ -85242,14 +85276,14 @@ const Rectangle DrawablePath::refreshFromValueTree (const ValueTree& tree return damageRect; } -const ValueTree DrawablePath::createValueTree (ImageProvider*) const +const ValueTree DrawablePath::createValueTree (ImageProvider* imageProvider) const { ValueTree tree (valueTreeType); ValueTreeWrapper v (tree); v.setID (getName(), 0); - v.setMainFill (mainFill, 0, 0, 0); - v.setStrokeFill (strokeFill, 0, 0, 0); + v.setMainFill (mainFill, 0, 0, imageProvider, 0); + v.setStrokeFill (strokeFill, 0, 0, imageProvider, 0); v.setStrokeType (strokeType, 0); if (relativePath != 0) @@ -93288,6 +93322,17 @@ const Image Image::convertedToFormat (PixelFormat newFormat) const return newImage; } +const var Image::getTag() const +{ + return image == 0 ? var::null : image->userTag; +} + +void Image::setTag (const var& newTag) +{ + if (image != 0) + image->userTag = newTag; +} + Image::BitmapData::BitmapData (Image& image, const int x, const int y, const int w, const int h, const bool /*makeWritable*/) : data (image.image == 0 ? 0 : image.image->getPixelData (x, y)), pixelFormat (image.getFormat()), @@ -253550,10 +253595,10 @@ bool juce_setThreadPriority (void* handle, int priority) int pri = ((maxp - minp) / 2) * (priority - 1) / 9; - if (param.__sched_priority >= (minp + (maxp - minp) / 2)) - param.__sched_priority = minp + ((maxp - minp) / 2) + pri; // (realtime) + if (param.sched_priority >= (minp + (maxp - minp) / 2)) + param.sched_priority = minp + ((maxp - minp) / 2) + pri; // (realtime) else - param.__sched_priority = minp + pri; // (high) + param.sched_priority = minp + pri; // (high) param.sched_priority = jlimit (1, 127, 1 + (priority * 126) / 11); return pthread_setschedparam ((pthread_t) handle, policy, ¶m) == 0; @@ -253620,13 +253665,13 @@ void Process::setPriority (ProcessPriority prior) maxp = sched_get_priority_max (policy); if (p < 2) - param.__sched_priority = 0; + param.sched_priority = 0; else if (p == 2 ) // Set to middle of lower realtime priority range - param.__sched_priority = minp + (maxp - minp) / 4; + param.sched_priority = minp + (maxp - minp) / 4; else // Set to middle of higher realtime priority range - param.__sched_priority = minp + (3 * (maxp - minp) / 4); + param.sched_priority = minp + (3 * (maxp - minp) / 4); pthread_setschedparam (pthread_self(), policy, ¶m); } diff --git a/juce_amalgamated.h b/juce_amalgamated.h index 5b8da0ceb7..867774fd69 100644 --- a/juce_amalgamated.h +++ b/juce_amalgamated.h @@ -64,7 +64,7 @@ */ #define JUCE_MAJOR_VERSION 1 #define JUCE_MINOR_VERSION 52 -#define JUCE_BUILDNUMBER 10 +#define JUCE_BUILDNUMBER 11 /** Current Juce version number. @@ -24182,6 +24182,9 @@ public: /** True if the image's format is RGB. */ bool isRGB() const throw() { return getFormat() == RGB; } + /** True if the image's format is a single-channel alpha map. */ + bool isSingleChannel() const throw() { return getFormat() == SingleChannel; } + /** True if the image contains an alpha-channel. */ bool hasAlphaChannel() const throw() { return getFormat() != RGB; } @@ -24219,6 +24222,8 @@ public: Call this if you want to draw onto the image, but want to make sure that this doesn't affect any other code that may be sharing the same data. + + @see getReferenceCount */ void duplicateIfShared(); @@ -24348,12 +24353,37 @@ public: void createSolidAreaMask (RectangleList& result, float alphaThreshold = 0.5f) const; + /** Returns a user-specified data item that was set with setTag(). + setTag() and getTag() allow you to attach an arbitrary identifier value to an + image. The value is shared between all Image object that are referring to the + same underlying image data object. + */ + const var getTag() const; + + /** Attaches a user-specified data item to this image, which can be retrieved using getTag(). + setTag() and getTag() allow you to attach an arbitrary identifier value to an + image. The value is shared between all Image object that are referring to the + same underlying image data object. + + Note that if this Image is null, this method will fail to store the data. + */ + void setTag (const var& newTag); + /** Creates a context suitable for drawing onto this image. Don't call this method directly! It's used internally by the Graphics class. */ LowLevelGraphicsContext* createLowLevelContext() const; - /** + /** Returns the number of Image objects which are currently referring to the same internal + shared image data. + + @see duplicateIfShared + */ + int getReferenceCount() const throw() { return image == 0 ? 0 : image->getReferenceCount(); } + + /** This is a base class for task-specific types of image. + + Don't use this class directly! It's used internally by the Image class. */ class SharedImage : public ReferenceCountedObject { @@ -24375,6 +24405,7 @@ public: const int width, height; int pixelStride, lineStride; uint8* imageData; + var userTag; uint8* getPixelData (int x, int y) const throw(); @@ -24384,13 +24415,9 @@ public: /** @internal */ SharedImage* getSharedImage() const throw() { return image; } - /** @internal */ explicit Image (SharedImage* instance); - /** @internal */ - int getReferenceCount() const throw() { return image->getReferenceCount(); } - juce_UseDebuggingNewOperator private: @@ -42844,14 +42871,16 @@ public: static const Identifier idProperty; static const FillType readFillType (const ValueTree& v, RelativePoint* gradientPoint1, RelativePoint* gradientPoint2, - RelativeCoordinate::NamedCoordinateFinder* nameFinder); + RelativeCoordinate::NamedCoordinateFinder* nameFinder, + ImageProvider* imageProvider); static void writeFillType (ValueTree& v, const FillType& fillType, const RelativePoint* gradientPoint1, const RelativePoint* gradientPoint2, + ImageProvider* imageProvider, UndoManager* undoManager); ValueTree state; - static const Identifier type, gradientPoint1, gradientPoint2, colour, radial, colours; + static const Identifier type, gradientPoint1, gradientPoint2, colour, radial, colours, imageId, imageOpacity; }; juce_UseDebuggingNewOperator @@ -58532,12 +58561,15 @@ public: const var getImageIdentifier() const; void setImageIdentifier (const var& newIdentifier, UndoManager* undoManager); + Value getImageIdentifierValue (UndoManager* undoManager); float getOpacity() const; void setOpacity (float newOpacity, UndoManager* undoManager); + Value getOpacityValue (UndoManager* undoManager); const Colour getOverlayColour() const; void setOverlayColour (const Colour& newColour, UndoManager* undoManager); + Value getOverlayColourValue (UndoManager* undoManager); const RelativePoint getTargetPositionForTopLeft() const; void setTargetPositionForTopLeft (const RelativePoint& newPoint, UndoManager* undoManager); @@ -58667,15 +58699,17 @@ public: public: ValueTreeWrapper (const ValueTree& state); - const FillType getMainFill (RelativeCoordinate::NamedCoordinateFinder* nameFinder) const; + const FillType getMainFill (RelativeCoordinate::NamedCoordinateFinder* nameFinder, + ImageProvider* imageProvider) const; ValueTree getMainFillState(); - void setMainFill (const FillType& newFill, const RelativePoint* gradientPoint1, - const RelativePoint* gradientPoint2, UndoManager* undoManager); + void setMainFill (const FillType& newFill, const RelativePoint* gradientPoint1, const RelativePoint* gradientPoint2, + ImageProvider* imageProvider, UndoManager* undoManager); - const FillType getStrokeFill (RelativeCoordinate::NamedCoordinateFinder* nameFinder) const; + const FillType getStrokeFill (RelativeCoordinate::NamedCoordinateFinder* nameFinder, + ImageProvider* imageProvider) const; ValueTree getStrokeFillState(); - void setStrokeFill (const FillType& newFill, const RelativePoint* gradientPoint1, - const RelativePoint* gradientPoint2, UndoManager* undoManager); + void setStrokeFill (const FillType& newFill, const RelativePoint* gradientPoint1, const RelativePoint* gradientPoint2, + ImageProvider* imageProvider, UndoManager* undoManager); const PathStrokeType getStrokeType() const; void setStrokeType (const PathStrokeType& newStrokeType, UndoManager* undoManager); diff --git a/src/core/juce_StandardHeader.h b/src/core/juce_StandardHeader.h index 6b98ce6d8d..cf3540030b 100644 --- a/src/core/juce_StandardHeader.h +++ b/src/core/juce_StandardHeader.h @@ -33,7 +33,7 @@ */ #define JUCE_MAJOR_VERSION 1 #define JUCE_MINOR_VERSION 52 -#define JUCE_BUILDNUMBER 10 +#define JUCE_BUILDNUMBER 11 /** Current Juce version number. diff --git a/src/gui/graphics/drawables/juce_Drawable.cpp b/src/gui/graphics/drawables/juce_Drawable.cpp index 632cc572c7..642c65fc2e 100644 --- a/src/gui/graphics/drawables/juce_Drawable.cpp +++ b/src/gui/graphics/drawables/juce_Drawable.cpp @@ -171,6 +171,8 @@ const Identifier Drawable::ValueTreeWrapperBase::gradientPoint2 ("point2"); const Identifier Drawable::ValueTreeWrapperBase::colour ("colour"); const Identifier Drawable::ValueTreeWrapperBase::radial ("radial"); const Identifier Drawable::ValueTreeWrapperBase::colours ("colours"); +const Identifier Drawable::ValueTreeWrapperBase::imageId ("imageId"); +const Identifier Drawable::ValueTreeWrapperBase::imageOpacity ("imageOpacity"); Drawable::ValueTreeWrapperBase::ValueTreeWrapperBase (const ValueTree& state_) : state (state_) @@ -186,7 +188,7 @@ const String Drawable::ValueTreeWrapperBase::getID() const return state [idProperty]; } -void Drawable::ValueTreeWrapperBase::setID (const String& newID, UndoManager* undoManager) +void Drawable::ValueTreeWrapperBase::setID (const String& newID, UndoManager* const undoManager) { if (newID.isEmpty()) state.removeProperty (idProperty, undoManager); @@ -194,8 +196,8 @@ void Drawable::ValueTreeWrapperBase::setID (const String& newID, UndoManager* un state.setProperty (idProperty, newID, undoManager); } -const FillType Drawable::ValueTreeWrapperBase::readFillType (const ValueTree& v, RelativePoint* gp1, RelativePoint* gp2, - RelativeCoordinate::NamedCoordinateFinder* nameFinder) +const FillType Drawable::ValueTreeWrapperBase::readFillType (const ValueTree& v, RelativePoint* const gp1, RelativePoint* const gp2, + RelativeCoordinate::NamedCoordinateFinder* const nameFinder, ImageProvider* imageProvider) { const String newType (v[type].toString()); @@ -231,7 +233,13 @@ const FillType Drawable::ValueTreeWrapperBase::readFillType (const ValueTree& v, } else if (newType == "image") { - jassertfalse; //xxx todo + Image im; + if (imageProvider != 0) + im = imageProvider->getImageForIdentifier (v[imageId]); + + FillType f (im, AffineTransform::identity); + f.setOpacity ((float) v.getProperty (imageOpacity, 1.0f)); + return f; } jassertfalse; @@ -239,8 +247,8 @@ const FillType Drawable::ValueTreeWrapperBase::readFillType (const ValueTree& v, } void Drawable::ValueTreeWrapperBase::writeFillType (ValueTree& v, const FillType& fillType, - const RelativePoint* gp1, const RelativePoint* gp2, - UndoManager* const undoManager) + const RelativePoint* const gp1, const RelativePoint* const gp2, + ImageProvider* imageProvider, UndoManager* const undoManager) { if (fillType.isColour()) { @@ -256,8 +264,8 @@ void Drawable::ValueTreeWrapperBase::writeFillType (ValueTree& v, const FillType String s; for (int i = 0; i < fillType.gradient->getNumColours(); ++i) - s << " " << fillType.gradient->getColourPosition (i) - << " " << String::toHexString ((int) fillType.gradient->getColour(i).getARGB()); + s << ' ' << fillType.gradient->getColourPosition (i) + << ' ' << String::toHexString ((int) fillType.gradient->getColour(i).getARGB()); v.setProperty (colours, s.trimStart(), undoManager); } @@ -265,7 +273,13 @@ void Drawable::ValueTreeWrapperBase::writeFillType (ValueTree& v, const FillType { v.setProperty (type, "image", undoManager); - jassertfalse; //xxx todo + if (imageProvider != 0) + v.setProperty (imageId, imageProvider->getIdentifierForImage (fillType.image), undoManager); + + if (fillType.getOpacity() < 1.0f) + v.setProperty (imageOpacity, fillType.getOpacity(), undoManager); + else + v.removeProperty (imageOpacity, undoManager); } else { diff --git a/src/gui/graphics/drawables/juce_Drawable.h b/src/gui/graphics/drawables/juce_Drawable.h index 702ba2d58f..7dcd6d1735 100644 --- a/src/gui/graphics/drawables/juce_Drawable.h +++ b/src/gui/graphics/drawables/juce_Drawable.h @@ -249,14 +249,16 @@ public: static const Identifier idProperty; static const FillType readFillType (const ValueTree& v, RelativePoint* gradientPoint1, RelativePoint* gradientPoint2, - RelativeCoordinate::NamedCoordinateFinder* nameFinder); + RelativeCoordinate::NamedCoordinateFinder* nameFinder, + ImageProvider* imageProvider); static void writeFillType (ValueTree& v, const FillType& fillType, const RelativePoint* gradientPoint1, const RelativePoint* gradientPoint2, + ImageProvider* imageProvider, UndoManager* undoManager); ValueTree state; - static const Identifier type, gradientPoint1, gradientPoint2, colour, radial, colours; + static const Identifier type, gradientPoint1, gradientPoint2, colour, radial, colours, imageId, imageOpacity; }; //============================================================================== diff --git a/src/gui/graphics/drawables/juce_DrawableImage.cpp b/src/gui/graphics/drawables/juce_DrawableImage.cpp index 05df608f09..d34b41820b 100644 --- a/src/gui/graphics/drawables/juce_DrawableImage.cpp +++ b/src/gui/graphics/drawables/juce_DrawableImage.cpp @@ -199,6 +199,11 @@ const var DrawableImage::ValueTreeWrapper::getImageIdentifier() const return state [image]; } +Value DrawableImage::ValueTreeWrapper::getImageIdentifierValue (UndoManager* undoManager) +{ + return state.getPropertyAsValue (image, undoManager); +} + void DrawableImage::ValueTreeWrapper::setImageIdentifier (const var& newIdentifier, UndoManager* undoManager) { state.setProperty (image, newIdentifier, undoManager); @@ -209,6 +214,14 @@ float DrawableImage::ValueTreeWrapper::getOpacity() const return (float) state.getProperty (opacity, 1.0); } +Value DrawableImage::ValueTreeWrapper::getOpacityValue (UndoManager* undoManager) +{ + if (! state.hasProperty (opacity)) + state.setProperty (opacity, 1.0, undoManager); + + return state.getPropertyAsValue (opacity, undoManager); +} + void DrawableImage::ValueTreeWrapper::setOpacity (float newOpacity, UndoManager* undoManager) { state.setProperty (opacity, newOpacity, undoManager); @@ -227,6 +240,11 @@ void DrawableImage::ValueTreeWrapper::setOverlayColour (const Colour& newColour, state.setProperty (overlay, String::toHexString ((int) newColour.getARGB()), undoManager); } +Value DrawableImage::ValueTreeWrapper::getOverlayColourValue (UndoManager* undoManager) +{ + return state.getPropertyAsValue (overlay, undoManager); +} + const RelativePoint DrawableImage::ValueTreeWrapper::getTargetPositionForTopLeft() const { const String pos (state [topLeft].toString()); diff --git a/src/gui/graphics/drawables/juce_DrawableImage.h b/src/gui/graphics/drawables/juce_DrawableImage.h index 45b808c823..d0b4d6bb99 100644 --- a/src/gui/graphics/drawables/juce_DrawableImage.h +++ b/src/gui/graphics/drawables/juce_DrawableImage.h @@ -134,12 +134,15 @@ public: const var getImageIdentifier() const; void setImageIdentifier (const var& newIdentifier, UndoManager* undoManager); + Value getImageIdentifierValue (UndoManager* undoManager); float getOpacity() const; void setOpacity (float newOpacity, UndoManager* undoManager); + Value getOpacityValue (UndoManager* undoManager); const Colour getOverlayColour() const; void setOverlayColour (const Colour& newColour, UndoManager* undoManager); + Value getOverlayColourValue (UndoManager* undoManager); const RelativePoint getTargetPositionForTopLeft() const; void setTargetPositionForTopLeft (const RelativePoint& newPoint, UndoManager* undoManager); diff --git a/src/gui/graphics/drawables/juce_DrawablePath.cpp b/src/gui/graphics/drawables/juce_DrawablePath.cpp index 2c0ba42b8f..e76624d24b 100644 --- a/src/gui/graphics/drawables/juce_DrawablePath.cpp +++ b/src/gui/graphics/drawables/juce_DrawablePath.cpp @@ -212,7 +212,7 @@ ValueTree DrawablePath::ValueTreeWrapper::getMainFillState() if (v.isValid()) return v; - setMainFill (Colours::black, 0, 0, 0); + setMainFill (Colours::black, 0, 0, 0, 0); return getMainFillState(); } @@ -222,32 +222,34 @@ ValueTree DrawablePath::ValueTreeWrapper::getStrokeFillState() if (v.isValid()) return v; - setStrokeFill (Colours::black, 0, 0, 0); + setStrokeFill (Colours::black, 0, 0, 0, 0); return getStrokeFillState(); } -const FillType DrawablePath::ValueTreeWrapper::getMainFill (RelativeCoordinate::NamedCoordinateFinder* nameFinder) const +const FillType DrawablePath::ValueTreeWrapper::getMainFill (RelativeCoordinate::NamedCoordinateFinder* nameFinder, + ImageProvider* imageProvider) const { - return readFillType (state.getChildWithName (fill), 0, 0, nameFinder); + return readFillType (state.getChildWithName (fill), 0, 0, nameFinder, imageProvider); } void DrawablePath::ValueTreeWrapper::setMainFill (const FillType& newFill, const RelativePoint* gp1, - const RelativePoint* gp2, UndoManager* undoManager) + const RelativePoint* gp2, ImageProvider* imageProvider, UndoManager* undoManager) { ValueTree v (state.getOrCreateChildWithName (fill, undoManager)); - writeFillType (v, newFill, gp1, gp2, undoManager); + writeFillType (v, newFill, gp1, gp2, imageProvider, undoManager); } -const FillType DrawablePath::ValueTreeWrapper::getStrokeFill (RelativeCoordinate::NamedCoordinateFinder* nameFinder) const +const FillType DrawablePath::ValueTreeWrapper::getStrokeFill (RelativeCoordinate::NamedCoordinateFinder* nameFinder, + ImageProvider* imageProvider) const { - return readFillType (state.getChildWithName (stroke), 0, 0, nameFinder); + return readFillType (state.getChildWithName (stroke), 0, 0, nameFinder, imageProvider); } void DrawablePath::ValueTreeWrapper::setStrokeFill (const FillType& newFill, const RelativePoint* gp1, - const RelativePoint* gp2, UndoManager* undoManager) + const RelativePoint* gp2, ImageProvider* imageProvider, UndoManager* undoManager) { ValueTree v (state.getOrCreateChildWithName (stroke, undoManager)); - writeFillType (v, newFill, gp1, gp2, undoManager); + writeFillType (v, newFill, gp1, gp2, imageProvider, undoManager); } const PathStrokeType DrawablePath::ValueTreeWrapper::getStrokeType() const @@ -283,6 +285,7 @@ void DrawablePath::ValueTreeWrapper::setUsesNonZeroWinding (bool b, UndoManager* state.setProperty (nonZeroWinding, b, undoManager); } +//============================================================================== const Identifier DrawablePath::ValueTreeWrapper::Element::startSubPathElement ("Move"); const Identifier DrawablePath::ValueTreeWrapper::Element::closeSubPathElement ("Close"); const Identifier DrawablePath::ValueTreeWrapper::Element::lineToElement ("Line"); @@ -342,14 +345,14 @@ const RelativePoint DrawablePath::ValueTreeWrapper::Element::getEndPoint() const //============================================================================== -const Rectangle DrawablePath::refreshFromValueTree (const ValueTree& tree, ImageProvider*) +const Rectangle DrawablePath::refreshFromValueTree (const ValueTree& tree, ImageProvider* imageProvider) { Rectangle damageRect; ValueTreeWrapper v (tree); setName (v.getID()); bool needsRedraw = false; - const FillType newFill (v.getMainFill (parent)); + const FillType newFill (v.getMainFill (parent, imageProvider)); if (mainFill != newFill) { @@ -357,7 +360,7 @@ const Rectangle DrawablePath::refreshFromValueTree (const ValueTree& tree mainFill = newFill; } - const FillType newStrokeFill (v.getStrokeFill (parent)); + const FillType newStrokeFill (v.getStrokeFill (parent, imageProvider)); if (strokeFill != newStrokeFill) { @@ -391,14 +394,14 @@ const Rectangle DrawablePath::refreshFromValueTree (const ValueTree& tree return damageRect; } -const ValueTree DrawablePath::createValueTree (ImageProvider*) const +const ValueTree DrawablePath::createValueTree (ImageProvider* imageProvider) const { ValueTree tree (valueTreeType); ValueTreeWrapper v (tree); v.setID (getName(), 0); - v.setMainFill (mainFill, 0, 0, 0); - v.setStrokeFill (strokeFill, 0, 0, 0); + v.setMainFill (mainFill, 0, 0, imageProvider, 0); + v.setStrokeFill (strokeFill, 0, 0, imageProvider, 0); v.setStrokeType (strokeType, 0); if (relativePath != 0) diff --git a/src/gui/graphics/drawables/juce_DrawablePath.h b/src/gui/graphics/drawables/juce_DrawablePath.h index 9968337adf..c81caa5fc4 100644 --- a/src/gui/graphics/drawables/juce_DrawablePath.h +++ b/src/gui/graphics/drawables/juce_DrawablePath.h @@ -129,15 +129,17 @@ public: public: ValueTreeWrapper (const ValueTree& state); - const FillType getMainFill (RelativeCoordinate::NamedCoordinateFinder* nameFinder) const; + const FillType getMainFill (RelativeCoordinate::NamedCoordinateFinder* nameFinder, + ImageProvider* imageProvider) const; ValueTree getMainFillState(); - void setMainFill (const FillType& newFill, const RelativePoint* gradientPoint1, - const RelativePoint* gradientPoint2, UndoManager* undoManager); + void setMainFill (const FillType& newFill, const RelativePoint* gradientPoint1, const RelativePoint* gradientPoint2, + ImageProvider* imageProvider, UndoManager* undoManager); - const FillType getStrokeFill (RelativeCoordinate::NamedCoordinateFinder* nameFinder) const; + const FillType getStrokeFill (RelativeCoordinate::NamedCoordinateFinder* nameFinder, + ImageProvider* imageProvider) const; ValueTree getStrokeFillState(); - void setStrokeFill (const FillType& newFill, const RelativePoint* gradientPoint1, - const RelativePoint* gradientPoint2, UndoManager* undoManager); + void setStrokeFill (const FillType& newFill, const RelativePoint* gradientPoint1, const RelativePoint* gradientPoint2, + ImageProvider* imageProvider, UndoManager* undoManager); const PathStrokeType getStrokeType() const; void setStrokeType (const PathStrokeType& newStrokeType, UndoManager* undoManager); diff --git a/src/gui/graphics/imaging/juce_Image.cpp b/src/gui/graphics/imaging/juce_Image.cpp index 16d48484ac..e84081081c 100644 --- a/src/gui/graphics/imaging/juce_Image.cpp +++ b/src/gui/graphics/imaging/juce_Image.cpp @@ -198,6 +198,16 @@ const Image Image::convertedToFormat (PixelFormat newFormat) const return newImage; } +const var Image::getTag() const +{ + return image == 0 ? var::null : image->userTag; +} + +void Image::setTag (const var& newTag) +{ + if (image != 0) + image->userTag = newTag; +} //============================================================================== Image::BitmapData::BitmapData (Image& image, const int x, const int y, const int w, const int h, const bool /*makeWritable*/) diff --git a/src/gui/graphics/imaging/juce_Image.h b/src/gui/graphics/imaging/juce_Image.h index 782b06b9b6..fdf39a61f4 100644 --- a/src/gui/graphics/imaging/juce_Image.h +++ b/src/gui/graphics/imaging/juce_Image.h @@ -28,6 +28,7 @@ #include "../colour/juce_Colour.h" #include "../contexts/juce_Graphics.h" +#include "../../../containers/juce_Variant.h" //============================================================================== @@ -159,6 +160,9 @@ public: /** True if the image's format is RGB. */ bool isRGB() const throw() { return getFormat() == RGB; } + /** True if the image's format is a single-channel alpha map. */ + bool isSingleChannel() const throw() { return getFormat() == SingleChannel; } + /** True if the image contains an alpha-channel. */ bool hasAlphaChannel() const throw() { return getFormat() != RGB; } @@ -197,6 +201,8 @@ public: Call this if you want to draw onto the image, but want to make sure that this doesn't affect any other code that may be sharing the same data. + + @see getReferenceCount */ void duplicateIfShared(); @@ -328,13 +334,40 @@ public: void createSolidAreaMask (RectangleList& result, float alphaThreshold = 0.5f) const; + //============================================================================== + /** Returns a user-specified data item that was set with setTag(). + setTag() and getTag() allow you to attach an arbitrary identifier value to an + image. The value is shared between all Image object that are referring to the + same underlying image data object. + */ + const var getTag() const; + + /** Attaches a user-specified data item to this image, which can be retrieved using getTag(). + setTag() and getTag() allow you to attach an arbitrary identifier value to an + image. The value is shared between all Image object that are referring to the + same underlying image data object. + + Note that if this Image is null, this method will fail to store the data. + */ + void setTag (const var& newTag); + + //============================================================================== /** Creates a context suitable for drawing onto this image. Don't call this method directly! It's used internally by the Graphics class. */ LowLevelGraphicsContext* createLowLevelContext() const; + /** Returns the number of Image objects which are currently referring to the same internal + shared image data. + + @see duplicateIfShared + */ + int getReferenceCount() const throw() { return image == 0 ? 0 : image->getReferenceCount(); } + //============================================================================== - /** + /** This is a base class for task-specific types of image. + + Don't use this class directly! It's used internally by the Image class. */ class SharedImage : public ReferenceCountedObject { @@ -356,6 +389,7 @@ public: const int width, height; int pixelStride, lineStride; uint8* imageData; + var userTag; uint8* getPixelData (int x, int y) const throw(); @@ -364,14 +398,10 @@ public: }; /** @internal */ - SharedImage* getSharedImage() const throw() { return image; } - + SharedImage* getSharedImage() const throw() { return image; } /** @internal */ explicit Image (SharedImage* instance); - /** @internal */ - int getReferenceCount() const throw() { return image->getReferenceCount(); } - //============================================================================== juce_UseDebuggingNewOperator diff --git a/src/native/linux/juce_linux_Threads.cpp b/src/native/linux/juce_linux_Threads.cpp index acfb3b82d9..8498bbaacd 100644 --- a/src/native/linux/juce_linux_Threads.cpp +++ b/src/native/linux/juce_linux_Threads.cpp @@ -100,10 +100,10 @@ bool juce_setThreadPriority (void* handle, int priority) int pri = ((maxp - minp) / 2) * (priority - 1) / 9; - if (param.__sched_priority >= (minp + (maxp - minp) / 2)) - param.__sched_priority = minp + ((maxp - minp) / 2) + pri; // (realtime) + if (param.sched_priority >= (minp + (maxp - minp) / 2)) + param.sched_priority = minp + ((maxp - minp) / 2) + pri; // (realtime) else - param.__sched_priority = minp + pri; // (high) + param.sched_priority = minp + pri; // (high) param.sched_priority = jlimit (1, 127, 1 + (priority * 126) / 11); return pthread_setschedparam ((pthread_t) handle, policy, ¶m) == 0; @@ -172,13 +172,13 @@ void Process::setPriority (ProcessPriority prior) maxp = sched_get_priority_max (policy); if (p < 2) - param.__sched_priority = 0; + param.sched_priority = 0; else if (p == 2 ) // Set to middle of lower realtime priority range - param.__sched_priority = minp + (maxp - minp) / 4; + param.sched_priority = minp + (maxp - minp) / 4; else // Set to middle of higher realtime priority range - param.__sched_priority = minp + (3 * (maxp - minp) / 4); + param.sched_priority = minp + (3 * (maxp - minp) / 4); pthread_setschedparam (pthread_self(), policy, ¶m); }