Skip to content

Commit

Permalink
Minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
dagronf committed Aug 6, 2024
1 parent 60ca1d9 commit f5b74cf
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 39 deletions.
2 changes: 1 addition & 1 deletion Bitmap.podspec
Original file line number Diff line number Diff line change
@@ -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' }
Expand Down
53 changes: 53 additions & 0 deletions Sources/Bitmap/drawing/Bitmap+InnerShadow.swift
Original file line number Diff line number Diff line change
@@ -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
}
}
38 changes: 0 additions & 38 deletions Sources/Bitmap/drawing/Bitmap+Shadow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit f5b74cf

Please sign in to comment.