mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-09 23:34:20 +00:00
macOS: Simplify the CoreGraphics pointer types and add some new ones
This commit is contained in:
parent
997c92797c
commit
25ee1b9e68
3 changed files with 28 additions and 51 deletions
|
|
@ -38,10 +38,9 @@
|
|||
namespace juce
|
||||
{
|
||||
|
||||
template <typename CFType>
|
||||
struct CFObjectDeleter
|
||||
{
|
||||
void operator() (CFType object) const noexcept
|
||||
void operator() (CFTypeRef object) const noexcept
|
||||
{
|
||||
if (object != nullptr)
|
||||
CFRelease (object);
|
||||
|
|
@ -49,7 +48,17 @@ struct CFObjectDeleter
|
|||
};
|
||||
|
||||
template <typename CFType>
|
||||
using CFUniquePtr = std::unique_ptr<std::remove_pointer_t<CFType>, CFObjectDeleter<CFType>>;
|
||||
struct CFRefRemover
|
||||
{
|
||||
static_assert (std::is_pointer_v<CFType>, "CFType must be a Ref type");
|
||||
using Type = std::remove_pointer_t<CFType>;
|
||||
};
|
||||
|
||||
template <typename CFType>
|
||||
using CFRemoveRef = typename CFRefRemover<CFType>::Type;
|
||||
|
||||
template <typename CFType>
|
||||
using CFUniquePtr = std::unique_ptr<CFRemoveRef<CFType>, CFObjectDeleter>;
|
||||
|
||||
template <typename CFType>
|
||||
struct CFObjectHolder
|
||||
|
|
|
|||
|
|
@ -37,43 +37,14 @@ namespace juce
|
|||
|
||||
namespace detail
|
||||
{
|
||||
struct ColorSpaceDelete
|
||||
{
|
||||
void operator() (CGColorSpaceRef ptr) const noexcept { CGColorSpaceRelease (ptr); }
|
||||
};
|
||||
|
||||
struct ContextDelete
|
||||
{
|
||||
void operator() (CGContextRef ptr) const noexcept { CGContextRelease (ptr); }
|
||||
};
|
||||
|
||||
struct DataProviderDelete
|
||||
{
|
||||
void operator() (CGDataProviderRef ptr) const noexcept { CGDataProviderRelease (ptr); }
|
||||
};
|
||||
|
||||
struct ImageDelete
|
||||
{
|
||||
void operator() (CGImageRef ptr) const noexcept { CGImageRelease (ptr); }
|
||||
};
|
||||
|
||||
struct GradientDelete
|
||||
{
|
||||
void operator() (CGGradientRef ptr) const noexcept { CGGradientRelease (ptr); }
|
||||
};
|
||||
|
||||
struct ColorDelete
|
||||
{
|
||||
void operator() (CGColorRef ptr) const noexcept { CGColorRelease (ptr); }
|
||||
};
|
||||
|
||||
//==============================================================================
|
||||
using ColorSpacePtr = std::unique_ptr<CGColorSpace, ColorSpaceDelete>;
|
||||
using ContextPtr = std::unique_ptr<CGContext, ContextDelete>;
|
||||
using DataProviderPtr = std::unique_ptr<CGDataProvider, DataProviderDelete>;
|
||||
using ImagePtr = std::unique_ptr<CGImage, ImageDelete>;
|
||||
using GradientPtr = std::unique_ptr<CGGradient, GradientDelete>;
|
||||
using ColorPtr = std::unique_ptr<CGColor, ColorDelete>;
|
||||
using ColorSpacePtr = CFUniquePtr<CGColorSpaceRef>;
|
||||
using ContextPtr = CFUniquePtr<CGContextRef>;
|
||||
using DataProviderPtr = CFUniquePtr<CGDataProviderRef>;
|
||||
using ImagePtr = CFUniquePtr<CGImageRef>;
|
||||
using GradientPtr = CFUniquePtr<CGGradientRef>;
|
||||
using ColorPtr = CFUniquePtr<CGColorRef>;
|
||||
using PathPtr = CFUniquePtr<CGPathRef>;
|
||||
using MutablePathPtr = CFUniquePtr<CGMutablePathRef>;
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
|
|||
|
|
@ -637,10 +637,9 @@ void CoreGraphicsContext::drawRoundedRectangle (const Rectangle<float>& r, float
|
|||
CGContextSetLineCap (context.get(), kCGLineCapButt);
|
||||
CGContextSetLineJoin (context.get(), kCGLineJoinMiter);
|
||||
|
||||
CGPathRef path = CGPathCreateWithRoundedRect (convertToCGRectFlipped (r), cornerSize, cornerSize, nullptr);
|
||||
CGContextAddPath (context.get(), path);
|
||||
detail::PathPtr path { CGPathCreateWithRoundedRect (convertToCGRectFlipped (r), cornerSize, cornerSize, nullptr) };
|
||||
CGContextAddPath (context.get(), path.get());
|
||||
drawCurrentPath (kCGPathStroke);
|
||||
CGPathRelease (path);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -652,28 +651,26 @@ void CoreGraphicsContext::drawRoundedRectangle (const Rectangle<float>& r, float
|
|||
const auto insideRect = r.reduced (lineThickness);
|
||||
const auto insideCornerSize = cornerSize - lineThickness;
|
||||
|
||||
CGMutablePathRef path = CGPathCreateMutable();
|
||||
CGPathAddRoundedRect (path, nullptr, convertToCGRectFlipped (outsideRect),
|
||||
detail::MutablePathPtr path { CGPathCreateMutable() };
|
||||
CGPathAddRoundedRect (path.get(), nullptr, convertToCGRectFlipped (outsideRect),
|
||||
jmin (outsideCornerSize, outsideRect.getWidth() / 2.0f),
|
||||
jmin (outsideCornerSize, outsideRect.getHeight() / 2.0f));
|
||||
|
||||
CGPathAddRoundedRect (path, nullptr, convertToCGRectFlipped (insideRect),
|
||||
CGPathAddRoundedRect (path.get(), nullptr, convertToCGRectFlipped (insideRect),
|
||||
jmin (insideCornerSize, insideRect.getWidth() / 2.0f),
|
||||
jmin (insideCornerSize, insideRect.getHeight() / 2.0f));
|
||||
|
||||
CGContextAddPath (context.get(), path);
|
||||
CGContextAddPath (context.get(), path.get());
|
||||
drawCurrentPath (kCGPathEOFill);
|
||||
CGPathRelease (path);
|
||||
}
|
||||
}
|
||||
|
||||
void CoreGraphicsContext::fillRoundedRectangle (const Rectangle<float>& r, float cornerSize)
|
||||
{
|
||||
CGContextBeginPath (context.get());
|
||||
CGPathRef path = CGPathCreateWithRoundedRect (convertToCGRectFlipped (r), cornerSize, cornerSize, nullptr);
|
||||
CGContextAddPath (context.get(), path);
|
||||
detail::PathPtr path { CGPathCreateWithRoundedRect (convertToCGRectFlipped (r), cornerSize, cornerSize, nullptr) };
|
||||
CGContextAddPath (context.get(), path.get());
|
||||
drawCurrentPath (kCGPathFill);
|
||||
CGPathRelease (path);
|
||||
}
|
||||
|
||||
void CoreGraphicsContext::drawLineWithThickness (const Line<float>& line, float lineThickness)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue