.../Source/Extensions/NSImage+fake.swift
Line  | Count  | Source  | 
1  |  | //  | 
2  |  | //  NSImage+fake.swift  | 
3  |  | //  CutBox  | 
4  |  | //  | 
5  |  | //  Created by jason on 13/9/23.  | 
6  |  | //  Copyright © 2023 ocodo. All rights reserved.  | 
7  |  | //  | 
8  |  |  | 
9  |  | import Cocoa  | 
10  |  |  | 
11  |  | extension NSImage { | 
12  | 334  |     static var fake: NSImage { | 
13  | 334  |         return createFakeImage(size: NSSize(width: 100, height: 100), color: .blue)  | 
14  | 334  |     }  | 
15  |  |  | 
16  | 1  |     static func fake(size: NSSize = NSSize(width: 100, height: 100), color: NSColor = .blue) -> NSImage { | 
17  | 1  |         return createFakeImage(size: size, color: color)  | 
18  | 1  |     }  | 
19  |  |  | 
20  | 335  |     private static func createFakeImage(size: NSSize, color: NSColor) -> NSImage { | 
21  | 335  |         let placeholderImage = NSImage(size: size)  | 
22  | 335  |  | 
23  | 335  |         placeholderImage.lockFocus()  | 
24  | 335  |         color.set()  | 
25  | 335  |         NSBezierPath(  | 
26  | 335  |             rect: NSRect(x: 0, y: 0,  | 
27  | 335  |                          width: size.width,  | 
28  | 335  |                          height: size.height)).fill()  | 
29  | 335  |         placeholderImage.unlockFocus()  | 
30  | 335  |  | 
31  | 335  |        return placeholderImage  | 
32  | 335  |     }  | 
33  |  | }  |