From f5b74cf6f5dce0062b2ba52ec8d7edfd6168e869 Mon Sep 17 00:00:00 2001 From: Darren Ford Date: Tue, 6 Aug 2024 10:29:26 +1000 Subject: [PATCH] Minor refactor --- Bitmap.podspec | 2 +- .../Bitmap/drawing/Bitmap+InnerShadow.swift | 53 +++++++++++++++++++ Sources/Bitmap/drawing/Bitmap+Shadow.swift | 38 ------------- 3 files changed, 54 insertions(+), 39 deletions(-) create mode 100644 Sources/Bitmap/drawing/Bitmap+InnerShadow.swift diff --git a/Bitmap.podspec b/Bitmap.podspec index 379898a..36ded55 100644 --- a/Bitmap.podspec +++ b/Bitmap.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = 'Bitmap' -s.version = '1.2.0' +s.version = '1.2.1' s.summary = 'A Swift-y convenience for loading, saving and manipulating bitmap images.' s.homepage = 'https://github.com/dagronf/Bitmap' s.license = { :type => 'MIT', :file => 'LICENSE' } diff --git a/Sources/Bitmap/drawing/Bitmap+InnerShadow.swift b/Sources/Bitmap/drawing/Bitmap+InnerShadow.swift new file mode 100644 index 0000000..4e781d8 --- /dev/null +++ b/Sources/Bitmap/drawing/Bitmap+InnerShadow.swift @@ -0,0 +1,53 @@ +// +// Copyright © 2024 Darren Ford. All rights reserved. +// +// MIT license +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +// documentation files (the "Software"), to deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or substantial +// portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS +// OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +import Foundation +import CoreGraphics + +// MARK: - Inner shadows + +public extension Bitmap { + /// Draw a path using an inner shadow + /// - Parameters: + /// - path: The path + /// - fillColor: The color to fill the path, or nil for no color + /// - shadow: The shadow definition + func drawInnerShadow(_ path: CGPath, fillColor: CGColor? = nil, shadow: Bitmap.Shadow) { + self.draw { ctx in + if let fillColor = fillColor { + ctx.setFillColor(fillColor) + ctx.addPath(path) + ctx.fillPath() + } + ctx.drawInnerShadow(in: path, shadowColor: shadow.color, offset: shadow.offset, blurRadius: shadow.blur) + } + } + + /// Create a new bitmap by drawing a path using an inner shadow + /// - Parameters: + /// - path: The path + /// - fillColor: The color to fill the path, or nil for no color + /// - shadow: The shadow definition + /// - Returns: A new bitmap + func drawingInnerShadow(_ path: CGPath, fillColor: CGColor? = nil, shadow: Bitmap.Shadow) throws -> Bitmap { + let copy = try self.copy() + copy.drawInnerShadow(path, fillColor: fillColor, shadow: shadow) + return copy + } +} diff --git a/Sources/Bitmap/drawing/Bitmap+Shadow.swift b/Sources/Bitmap/drawing/Bitmap+Shadow.swift index 0d64134..9f32af5 100644 --- a/Sources/Bitmap/drawing/Bitmap+Shadow.swift +++ b/Sources/Bitmap/drawing/Bitmap+Shadow.swift @@ -52,41 +52,3 @@ public extension Bitmap { } } } - -// MARK: - Inner shadows - -public extension Bitmap { - /// Draw a path using an inner shadow - /// - Parameters: - /// - path: The path - /// - fillColor: The color to fill the path, or nil for no color - /// - shadow: The shadow definition - func drawInnerShadow(_ path: CGPath, fillColor: CGColor? = nil, shadow: Bitmap.Shadow) { - self.draw { ctx in - if let fillColor = fillColor { - ctx.setFillColor(fillColor) - ctx.addPath(path) - ctx.fillPath() - } - - ctx.drawInnerShadow( - in: path, - shadowColor: shadow.color, - offset: shadow.offset, - blurRadius: shadow.blur - ) - } - } - - /// Create a new bitmap by drawing a path using an inner shadow - /// - Parameters: - /// - path: The path - /// - fillColor: The color to fill the path, or nil for no color - /// - shadow: The shadow definition - /// - Returns: A new bitmap - func drawingInnerShadow(_ path: CGPath, fillColor: CGColor? = nil, shadow: Bitmap.Shadow) throws -> Bitmap { - let copy = try self.copy() - copy.drawInnerShadow(path, fillColor: fillColor, shadow: shadow) - return copy - } -}