Advertisement
frentzy

temporar proiect drag'n'drop

Jun 22nd, 2018
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 26.34 KB | None | 0 0
  1. //
  2. //  ViewController.swift
  3. //  test
  4. //
  5. //  Created by Frentescu Stefan on 21/06/2018.
  6. //  Copyright © 2018 Frentescu Stefan. All rights reserved.
  7. //
  8.  
  9. import Foundation
  10. import Cocoa
  11. import CoreImage
  12. @_exported import AppKit
  13.  
  14. extension NSImage {
  15. //    func imageWithTintColor(tintColor: NSColor) -> NSImage {
  16. //        if self.isTemplate == false {
  17. //            return self
  18. //        }
  19. //
  20. //        let image = self.copy() as! NSImage
  21. //        image.lockFocus()
  22. //
  23. //        tintColor.set()
  24. //        __NSRectFillUsingOperation(NSMakeRect(0, 0, image.size.width, image.size.height), NSCompositingOperation.sourceAtop)
  25. //        //        NSRect.CompositeSourceAtop
  26. //       // var a = NSColor.setFill(tintColor)// NSRect.fill(NSMakeRect(0, 0, image.size.width, image.size.height))
  27. //        //image.backgroundColor = NSColor.green
  28. //        //print(type(of:a))
  29. //
  30. //        image.unlockFocus()
  31. //        image.isTemplate = false
  32. //        return image
  33. //    }
  34.     func imageWithTintColor(tintColor: NSColor) -> NSImage {
  35.         if self.isTemplate == false {
  36.             return self
  37.         }
  38.        
  39.         let image = self.copy() as! NSImage
  40.         image.lockFocus()
  41.        
  42.         tintColor.set()
  43.         __NSRectFillUsingOperation(NSMakeRect(0, 0, image.size.width, image.size.height), NSCompositingOperation.sourceAtop)
  44.        
  45.         image.unlockFocus()
  46.         image.isTemplate = false
  47.        
  48.         return image
  49.     }
  50.    
  51.     func tinting(with tintColor: NSColor) -> NSImage {
  52.         guard let cgImage = self.cgImage(forProposedRect: nil, context: nil, hints: nil) else { return self }
  53.        
  54.         return NSImage(size: size, flipped: false) { bounds in
  55.             guard let context = NSGraphicsContext.current?.cgContext else { return false }
  56.            
  57.             tintColor.set()
  58.             context.clip(to: bounds, mask: cgImage)
  59.             context.fill(bounds)
  60.            
  61.             return true
  62.         }
  63.     }
  64.    
  65.     func tintedImage(_ image: NSImage, tint: NSColor) -> NSImage {
  66.         guard let tinted = image.copy() as? NSImage else { return image }
  67.         tinted.lockFocus()
  68.         tint.set()
  69.        
  70.         let imageRect = NSRect(origin: NSZeroPoint, size: image.size)
  71.         __NSRectFillUsingOperation(imageRect, .sourceAtop)
  72.        
  73.         tinted.unlockFocus()
  74.         return tinted
  75.     }
  76.    
  77.    
  78. }
  79.  
  80.  
  81. extension NSRect {
  82.     /// Fills this rect in the current NSGraphicsContext in the context's fill
  83.     /// color.
  84.     /// The compositing operation of the fill defaults to the context's
  85.     /// compositing operation, not necessarily using `.copy` like `NSRectFill()`.
  86.     /// - precondition: There must be a set current NSGraphicsContext.
  87.     @available(swift 4)
  88.     public func fill(using operation: NSCompositingOperation =
  89.         NSGraphicsContext.current?.compositingOperation ?? .sourceOver) {
  90.         precondition(NSGraphicsContext.current != nil,
  91.                      "There must be a set current NSGraphicsContext")
  92.         __NSRectFillUsingOperation(self, operation)
  93.     }
  94. }
  95.  
  96. class StatusIconImage{
  97.    
  98.     var item:NSStatusItem?
  99.     var image = NSImage()
  100.    
  101.     func initFunc(){
  102.        
  103.         let resizeImg:NSImage = image.copy() as! NSImage
  104.         resizeImg.size.width = 16
  105.         resizeImg.size.height = 16
  106.         item = NSStatusBar.system.statusItem(withLength: 30)
  107.         item?.image = resizeImg
  108.        
  109.     }
  110. }
  111.  
  112. class ExportImage{
  113.     var image:NSImage?
  114.     var url:URL?
  115.    
  116.     func url(url:String){
  117.         self.url = URL(fileURLWithPath: url)
  118.     }
  119.    
  120.     func resize(sizeImage:Int){
  121.         let resizedImage = image?.resize(image: image!, w: sizeImage, h: sizeImage)
  122.         image = resizedImage
  123.     }
  124.    
  125.     func export() {
  126.         image?.writePNG(toURL: url!)
  127.     }
  128. }
  129.  
  130. class ColorPanel {
  131.     var panel = NSColorPanel.shared
  132.    
  133.     func initFunc() {
  134.         panel.setTarget(self)
  135.         panel.makeKeyAndOrderFront(self)
  136.         panel.isContinuous = true
  137.     }
  138.     func changeColor(image:NSImage) -> NSImage{
  139.         return image.tintedImage(image, tint: panel.color)
  140.     }
  141. }
  142.  
  143.  
  144.  
  145. class ViewController: NSViewController {
  146.     @IBOutlet weak var imageDockController: NSImageView!
  147.     @IBOutlet weak var imageStatusController: NSImageView!
  148.     @IBOutlet weak var sliderDockController: NSSlider!
  149.     @IBOutlet weak var sliderStatusController: NSSlider!
  150.     @IBOutlet weak var BlackButton: NSButton!
  151.     @IBOutlet weak var disclosureController: NSButton!
  152.     @IBOutlet weak var LabelTextStatus1: NSTextField!
  153.     @IBOutlet weak var labelTextStatus2: NSTextField!
  154.     @IBOutlet weak var labelTextStatus3: NSTextField!
  155.     @IBOutlet weak var labelTextDock1: NSTextField!
  156.     @IBOutlet weak var labelTextDock2: NSTextField!
  157.     @IBOutlet weak var labelTextDock3: NSTextField!
  158.     @IBOutlet weak var colorPickIconDock: NSButton!
  159.     @IBOutlet weak var colorPickIconStatus: NSButton!
  160.    
  161.     @IBOutlet weak var exportButtonStatus: NSButton!
  162.     @IBOutlet weak var exportButtonDock: NSButton!
  163.     @IBOutlet weak var exportButtonStatusICNS: NSButton!
  164.     @IBOutlet weak var exportButtonDockICNS: NSButton!
  165.    
  166.     @IBOutlet var backgroundView: CustomView!
  167.    
  168.     var copyImageDockController: NSImage!
  169.     var copyImageStatusController: NSImage!
  170.     var statusController = StatusIconImage()
  171.     var statusImg:StatusIconImage?
  172.     var colorPick = ColorPanel()
  173.     var enabled = true
  174.     override func viewDidLoad() {
  175.         super.viewDidLoad()
  176.         BlackButton.title = "Black"
  177.         viewController.sliderDockController = sliderDockController
  178.         imageStatusController.image = #imageLiteral(resourceName: "uploadDrag'n'Drop")
  179.         imageDockController.image = #imageLiteral(resourceName: "uploadDrag'n'Drop")
  180.         copyImageDockController = #imageLiteral(resourceName: "uploadDrag'n'Drop")
  181.         copyImageStatusController = #imageLiteral(resourceName: "uploadDrag'n'Drop")
  182.         BlackButton.attributedTitle = NSMutableAttributedString(string: "Black",attributes:[NSAttributedStringKey.foregroundColor: NSColor.darkGray])
  183.         // Do any additional setup after loading the view.
  184.     }
  185.  
  186.     override func changeColor(_ sender: Any?) {
  187.  
  188.         if pozaTestIcon.state == NSControl.StateValue.on  {
  189.             poza1.image = colorPick.changeColor(image: poza1.image!)
  190.             pozaTestICon2.state = NSControl.StateValue.off
  191. //            iOSBackgroundLogo = imageDockController.image
  192.             iOSBackgroundLogo = poza1.image
  193.         } else if pozaTestICon2.state == NSControl.StateValue.on {
  194.             poza2.image = colorPick.changeColor(image: poza2.image!)
  195.             pozaTestIcon.state = NSControl.StateValue.off
  196.             iOSLogoIcon = poza2.image
  197.         }
  198.        
  199.        
  200.         if colorPickIconDock.state == NSControl.StateValue.on {
  201.             imageDockController.image = colorPick.changeColor(image: imageDockController.image!)
  202.            
  203.             copyImageDockController = imageDockController.image
  204.             sliderDockController.doubleValue = 100
  205.             colorPickIconStatus.state = NSControl.StateValue.off
  206.           //  colorPickIconDock.state = NSControl.StateValue.off
  207.         } else if colorPickIconStatus.state == NSControl.StateValue.on {
  208.             imageStatusController.image = colorPick.changeColor(image: imageStatusController.image!)
  209.             iOSLogoIcon = imageStatusController.image
  210.             copyImageStatusController = imageStatusController.image
  211.             sliderStatusController.doubleValue = 100
  212.             colorPickIconDock.state = NSControl.StateValue.off
  213. //colorPickIconStatus.state = NSControl.StateValue.off
  214.         }
  215.     }
  216.    
  217.     override var representedObject: Any? {
  218.         didSet {
  219.          //   print("test")
  220.             // Update the view, if already loaded.
  221.         }
  222.     }
  223.     override func prepare(for segue: NSStoryboardSegue, sender: Any?) {
  224.         disclosureController.state = NSControl.StateValue(0)
  225.         iOSBackgroundLogo = poza1.image
  226.         iOSLogoIcon = poza2.image
  227.        
  228.     }
  229.     //override func segue
  230.     override func cursorUpdate(with event: NSEvent) {
  231.         print("test")
  232.     }
  233.    
  234. //    @IBAction func menuSelectController(_ sender: NSPopUpButton) {
  235. //        func exportButtonTrueOrFalse(_ True:Bool) {
  236. //
  237. //            exportButtonDock.isHidden = !True
  238. //            exportButtonStatus.isHidden = True
  239. //            labelTextController1.isHidden = !True
  240. //            labelTextController2.isHidden = True
  241. //            imageDockController.isHidden = !True
  242. //            imageStatusController.isHidden = True
  243. //            sliderDockController.isHidden = !True
  244. //            sliderStatusController.isHidden = True
  245. //            exportButtonDockICNS.isHidden = !True
  246. //            exportButtonStatusICNS.isHidden = True
  247. //            sender.preferredEdge = NSRectEdge.init(rawValue: 1)!
  248. //        }
  249. //        if sender.indexOfSelectedItem == 0 {
  250. //            exportButtonTrueOrFalse(true)
  251. //        }
  252. //        if sender.indexOfSelectedItem == 1 {
  253. //            exportButtonTrueOrFalse(false)
  254. //        }
  255. //    }
  256.    
  257.     @IBAction func grayScaleImage(_ sender: NSSlider) {
  258.         if sender == sliderDockController {
  259.         let level = NSImage.imageBlackAndWhite(copyImageDockController)
  260.  
  261.         imageDockController.image = (copyImageDockController.copy() as! NSImage)
  262.         imageDockController.image = level(sender.doubleValue/100)
  263.         changeDockImage()
  264.        
  265.         } else {
  266.             let level = NSImage.imageBlackAndWhite(copyImageStatusController)
  267.             imageStatusController.image = (copyImageStatusController.copy() as! NSImage)
  268.             imageStatusController.image = level(sender.doubleValue/100)
  269.             changeStatusIconImage()
  270.         }
  271.     }
  272.    
  273.     @IBAction func exportImage(_ sender: NSButton) {
  274.         if sender == exportButtonDock {
  275.         let manager = FileManager.default
  276.         if let tempURLDirectory:URL = URL(fileURLWithPath: NSHomeDirectory() + "/Desktop/IconsDock") {
  277.             do {
  278.                 try manager.createDirectory(at: tempURLDirectory, withIntermediateDirectories: true)
  279.             }catch _ {
  280.                 print("The directory couldn't be created at \(tempURLDirectory) ")
  281.             }
  282.         }
  283.             let sizesArray = [16:"16.png",32:"32.png",64:"64.png",128:"128.png",256:"256.png",512:"512.png",1024:"1024.png"]
  284.             let iconExport = ExportImage()
  285.             let iconDirectoryURL = NSHomeDirectory() + "/Desktop/IconsDock/"
  286.             for (itemInt,itemString) in sizesArray {
  287.                 iconExport.url(url: iconDirectoryURL + "IconDock" + itemString)
  288.                 iconExport.image = imageDockController.image
  289.                 iconExport.resize(sizeImage: itemInt)
  290.                 iconExport.export()
  291.             }
  292.         } else if sender == exportButtonStatus{
  293.             let manager = FileManager.default
  294.             if let tempURLDirectory:URL = URL(fileURLWithPath: NSHomeDirectory() + "/Desktop/IconsStatus") {
  295.                
  296.                 do {
  297.                     try manager.createDirectory(at: tempURLDirectory, withIntermediateDirectories: true)
  298.                 }catch _ {
  299.                     print("The directory couldn't be created at \(tempURLDirectory) ")
  300.                 }
  301.             }
  302.             //  var testIconSet = Iconset()
  303.             let sizesArray = [16:"16.png",32:"32.png",128:"128.png",256:"256.png",512:"512.png",1024:"1024.png"]
  304.             let iconExport = ExportImage()
  305.            
  306.             let iconDirectoryURL = NSHomeDirectory() + "/Desktop/IconsStatus/"
  307.             for (itemInt,itemString) in sizesArray {
  308.                 iconExport.url(url: iconDirectoryURL + "IconStatus" + itemString)
  309.                 iconExport.image = imageStatusController.image
  310.                 iconExport.resize(sizeImage: itemInt)
  311.                 iconExport.export()
  312.                
  313.             }
  314.         }
  315.     }
  316.    
  317.     @IBAction func exportICNS(_ sender: NSButton) {
  318. //        if sender == exportButtonDockICNS {
  319. //            print("yes")
  320. //        }
  321. //        if sender == exportButtonStatusICNS {
  322. //            print("no")
  323. //        }
  324. //        var testIconSet = Iconset()
  325. //        let iconExportICNS = ExportImage()
  326. //        var iconDirectoryURL = String()
  327. //        if sender == exportButtonStatusICNS {
  328. //            iconDirectoryURL = NSHomeDirectory() + "/Desktop/IconStatus/"
  329. //        } else {
  330. //            iconDirectoryURL = NSHomeDirectory() + "/Desktop/IconDock/"
  331. //        }
  332. //        let sizesArrayICNS = [32:"32.png",64:"64.png",128:"128.png",256:"256.png",512:"512.png",1024:"1024.png"]
  333. //        for(itemInt,_) in sizesArrayICNS {
  334. //            if sender == exportButtonStatusICNS {
  335. //            iconExportICNS.image = imageStatusController.image
  336. //            } else if sender == exportButtonDockICNS {
  337. //            iconExportICNS.image = imageDockController.image
  338. //            }
  339. //            iconExportICNS.resize(sizeImage: itemInt/2)
  340. //            let iconImage = IconImage.init(iconExportICNS.image, withSize: NSSize(width: itemInt/2, height: itemInt/2), andScale: .scale1x)
  341. //            if sender == exportButtonStatusICNS {
  342. //                iconExportICNS.image = imageStatusController.image
  343. //            } else if sender == exportButtonDockICNS {
  344. //                iconExportICNS.image = imageDockController.image
  345. //            }
  346. //            iconExportICNS.resize(sizeImage: itemInt)
  347. //            let iconImage2x = IconImage.init(iconExportICNS.image, withSize: NSSize(width: itemInt, height: itemInt), andScale: .scale2x)
  348. //            let filename1x = iconImage!.filename
  349. //            let filename2x = iconImage2x!.filename
  350. //
  351. //
  352. //            testIconSet[filename1x] = iconImage
  353. //            testIconSet[filename2x] = iconImage2x
  354. //        }
  355. //        do {
  356. //            try testIconSet.writeToURL(URL(fileURLWithPath: iconDirectoryURL) )
  357. //        }catch _ {
  358. //            print("The operation couldn't be executed")
  359. //        }
  360.        
  361.         var icon = ""
  362.         var url = ""
  363.         if sender == exportButtonDockICNS {
  364.             let manager = FileManager.default
  365.              url = NSHomeDirectory() + "/Desktop/IconDockLogo.appiconset/"
  366.                 do {
  367.                     try manager.createDirectory(at: URL(fileURLWithPath: url), withIntermediateDirectories: true)
  368.                 }catch _ {
  369.                     print("The directory couldn't be created at \(url) ")
  370.                 }
  371.            
  372.             icon = "IconDock"
  373.            
  374.          //   let manager = FileManager.default
  375.           //  if let tempURLDirectory:URL = URL(fileURLWithPath: NSHomeDirectory() + "/Desktop/IconsDock") {
  376.                 do {
  377.                     try manager.createDirectory(at: URL(fileURLWithPath: "url"), withIntermediateDirectories: true)
  378.                 }catch _ {
  379.                     print("The directory couldn't be created at \(url) ")
  380.                 }
  381.            
  382.             let sizesArray = [16:"16.png",32:"32.png",64:"64.png",128:"128.png",256:"256.png",512:"512.png",1024:"1024.png"]
  383.             let iconExport = ExportImage()
  384.            // let iconDirectoryURL = NSHomeDirectory() + "/Desktop/IconsDock/"
  385.             for (itemInt,itemString) in sizesArray {
  386.                 iconExport.url(url: url  + "IconDock" + itemString)
  387.                 iconExport.image = imageDockController.image
  388.                 iconExport.resize(sizeImage: itemInt)
  389.                 iconExport.export()
  390.             }
  391.         } else {
  392.             let manager = FileManager.default
  393.             url = NSHomeDirectory() + "/Desktop/IconStatusLogo.appiconset/"
  394.             do {
  395.                 try manager.createDirectory(at: URL(fileURLWithPath: url), withIntermediateDirectories: true)
  396.             }catch _ {
  397.                 print("The directory couldn't be created at \(url) ")
  398.             }
  399.            
  400.             icon = "IconStatus"
  401.            
  402.             //   let manager = FileManager.default
  403.             //  if let tempURLDirectory:URL = URL(fileURLWithPath: NSHomeDirectory() + "/Desktop/IconsDock") {
  404.             do {
  405.                 try manager.createDirectory(at: URL(fileURLWithPath: "url"), withIntermediateDirectories: true)
  406.             }catch _ {
  407.                 print("The directory couldn't be created at \(url) ")
  408.             }
  409.            
  410.             let sizesArray = [16:"16.png",32:"32.png",64:"64.png",128:"128.png",256:"256.png",512:"512.png",1024:"1024.png"]
  411.             let iconExport = ExportImage()
  412.             // let iconDirectoryURL = NSHomeDirectory() + "/Desktop/IconsDock/"
  413.             for (itemInt,itemString) in sizesArray {
  414.                 iconExport.url(url: url  + "IconStatus" + itemString)
  415.                 iconExport.image = imageDockController.image
  416.                 iconExport.resize(sizeImage: itemInt)
  417.                 iconExport.export()
  418.             }
  419.         }
  420.         let str = """
  421.        {
  422.        "images" : [
  423.        {
  424.        "idiom" : "mac",
  425.        "size" : "16x16",
  426.        "filename" : "\(icon)16.png",
  427.        "scale" : "1x"
  428.        },
  429.        {
  430.        "idiom" : "mac",
  431.        "size" : "16x16",
  432.        "filename" : "\(icon)32.png",
  433.        "scale" : "2x"
  434.        },
  435.        {
  436.        "idiom" : "mac",
  437.        "size" : "32x32",
  438.        "filename" : "\(icon)32.png",
  439.        "scale" : "1x"
  440.        },
  441.        {
  442.        "idiom" : "mac",
  443.        "size" : "32x32",
  444.        "filename" : "\(icon)64.png",
  445.        "scale" : "2x"
  446.        },
  447.        {
  448.        "idiom" : "mac",
  449.        "size" : "128x128",
  450.        "filename" : "\(icon)128.png",
  451.        "scale" : "1x"
  452.        },
  453.        {
  454.        "idiom" : "mac",
  455.        "size" : "128x128",
  456.        "filename" : "\(icon)256.png",
  457.        "scale" : "2x"
  458.        },
  459.        {
  460.        "size" : "256x256",
  461.        "idiom" : "mac",
  462.        "filename" : "\(icon)256.png",
  463.        "scale" : "1x"
  464.        },
  465.        {
  466.        "idiom" : "mac",
  467.        "size" : "256x256",
  468.        "filename" : "\(icon)512.png",
  469.        "scale" : "2x"
  470.        },
  471.        {
  472.        "idiom" : "mac",
  473.        "size" : "512x512",
  474.        "filename" : "\(icon)512.png",
  475.        "scale" : "1x"
  476.        },
  477.        {
  478.        "idiom" : "mac",
  479.        "size" : "512x512",
  480.        "filename" : "\(icon)1024.png",
  481.        "scale" : "2x"
  482.        }
  483.        ],
  484.        "info" : {
  485.        "version" : 1,
  486.        "author" : "xcode"
  487.        }
  488.        }
  489.        """
  490.        
  491.         let filename = URL(fileURLWithPath: "\(String(describing: url))/Contents.json")
  492.         do {
  493.             try str.write(to: filename, atomically: true, encoding: String.Encoding.utf8)
  494.         } catch {
  495.             print("Failed to write the file at \(filename)")
  496.         }
  497.     }
  498.    
  499.    
  500.     @IBAction func whiteAndBlackBackground(_ sender: NSButton) {
  501.        
  502.         if sender.state == NSButton.StateValue.off{
  503.       //      backgroundView.bgColor = NSColor.init(white: CGFloat.init(1), alpha: CGFloat.init(0))
  504. //            backgroundView.
  505.             LabelTextStatus1.textColor = NSColor.black
  506.             labelTextStatus2.textColor = NSColor.black
  507.             labelTextStatus3.textColor = NSColor.black
  508.             labelTextDock1.textColor = NSColor.black
  509.             labelTextDock2.textColor = NSColor.black
  510.             labelTextDock3.textColor = NSColor.black
  511.             var tempIcon = colorPickIconDock.image
  512.             tempIcon = tempIcon?.tintedImage(tempIcon!, tint: NSColor.black)
  513.             colorPickIconDock.image = tempIcon
  514.             colorPickIconStatus.image = tempIcon
  515.             sender.attributedTitle = NSMutableAttributedString(string: "Black",attributes: [NSAttributedStringKey.foregroundColor: NSColor.black])
  516.             butonel.state = NSControl.StateValue.on
  517.         }else {
  518.            // backgroundView.bgColor = NSColor.darkGray
  519.             LabelTextStatus1.textColor = NSColor.lightGray
  520.             labelTextStatus2.textColor = NSColor.lightGray
  521.             labelTextStatus3.textColor = NSColor.lightGray
  522.             labelTextDock1.textColor = NSColor.lightGray
  523.             labelTextDock2.textColor = NSColor.lightGray
  524.             labelTextDock3.textColor = NSColor.lightGray
  525.            
  526.             var tempIcon = colorPickIconDock.image
  527.             tempIcon = tempIcon?.tintedImage(tempIcon!, tint: NSColor.lightGray)
  528.             colorPickIconDock.image = tempIcon
  529.             colorPickIconStatus.image = tempIcon
  530.             butonel.state = NSControl.StateValue.off
  531.            
  532.            
  533. //
  534.          //   sender.attributedTitle = NSMutableAttributedString(string: "Black",attributes: [NSAttributedStringKey.foregroundColor: NSColor.lightGray])
  535.        
  536.         }
  537.     }
  538.    
  539.     func changeDockImage(){
  540.         var dockIcon:NSImage = imageDockController.image!.copy() as! NSImage
  541.         dockIcon = dockIcon.resize(image: dockIcon, w: 256, h: 256)
  542.        
  543. //        dockIcon.size.height = 256
  544. //        dockIcon.size.width = 256
  545.         NSApp.applicationIconImage = dockIcon
  546.     }
  547.    
  548.     func changeStatusIconImage(){
  549.         let statusIconImage:NSImage = imageStatusController.image!.copy() as! NSImage
  550.         statusIconImage.size.width = 32
  551.         statusIconImage.size.height = 32
  552.        
  553.         statusController.image = statusIconImage
  554.         statusController.initFunc()
  555.         statusController.image = statusIconImage
  556.     }
  557.    
  558.     @IBAction func getInfoImage(_ sender: NSImageView) {
  559.         if sender == imageDockController {
  560.             sliderDockController.doubleValue = 100
  561.             sliderDockController.isHidden = false
  562.             copyImageDockController = sender.image
  563.             changeDockImage()
  564.             iOSBackgroundLogo = imageDockController.image
  565.         }else {
  566.          //   LabelTextStatus1.isHidden = true
  567.             sliderStatusController.doubleValue = 100
  568.             sliderStatusController.isHidden = false
  569.             copyImageStatusController = sender.image
  570.             changeStatusIconImage()
  571.             iOSLogoIcon = imageStatusController.image
  572.         }
  573.     }
  574.  
  575.  
  576.     func convertCIImageToNSImage(image: CIImage) -> NSImage {
  577.         //                let rep = NSCIImageRep(CIImage: image)
  578.         let rep = NSCIImageRep(ciImage: image)
  579.         let nsImage = NSImage(size: image.extent.size)
  580.         nsImage.addRepresentation(rep)
  581.         return nsImage
  582.     }
  583.     func convertNSimageToCIImage(image: NSImage) -> CIImage {
  584.         //            let monalisa = NSImage(named: NSImage.Name(rawValue: "monalisa.jpg"))!
  585.         let tiffData = image.tiffRepresentation!
  586.         let bitmap = NSBitmapImageRep(data: tiffData)
  587.         return CIImage(bitmapImageRep: bitmap!)!
  588.     }
  589.     func filter(name: String, inputImage: CIImage) -> CIImage {
  590.         let filter = CIFilter(name: name)
  591.         filter?.setDefaults()
  592.        
  593.         filter?.setValue(inputImage, forKey: kCIInputImageKey)
  594.         //  configure(filter!)
  595.         return filter!.outputImage!
  596.     }
  597.    
  598.     @IBAction func colorPickInit(_ sender: NSButton) {
  599.         colorPick.initFunc()
  600.         if sender == colorPickIconDock {
  601.             colorPickIconDock.state = NSControl.StateValue.on
  602.             colorPickIconStatus.state = NSControl.StateValue.off
  603.         } else {
  604.             colorPickIconStatus.state = NSControl.StateValue.on
  605.             colorPickIconDock.state = NSControl.StateValue.off
  606.         }
  607.         test()
  608.         let dataOfView = view.dataWithPDF(inside: view.bounds)
  609.         let imageOfView = NSImage(data: dataOfView)
  610.         imageOfView?.writePNG(toURL: URL(fileURLWithPath: NSHomeDirectory() + "/Desktop/testingView.png"))
  611.        
  612.     }
  613.    
  614.     func test () {
  615. //        NSGraphicsContext.current.
  616. //     imageDockController.image?.draw(in: imageStatusController.bounds)
  617. //        NSGraphicsContext.current
  618.         NSGraphicsContext.initialize()
  619.         NSGraphicsContext.init()
  620.         if NSGraphicsContext.currentContextDrawingToScreen() {
  621.             print("yes")
  622.         } else {
  623.             print("no")
  624.         }
  625.          var test = copyImageDockController.representations
  626.         print(type(of:test))
  627.         var integer = 0
  628.         for _ in test {
  629.             integer += 1
  630.            
  631.           //  print(index)
  632.         }
  633.         print(integer)
  634.        
  635.         imageDockController.image?.drawRepresentation(test[0], in: imageDockController.bounds)
  636.        
  637. //        NSDrawDarkBezel(NSRect.init(x: 0, y: 0, width: 100, height: 100), NSZeroRect)
  638. //        imageDockController.image?.draw(at: NSPoint.init(x: 100, y: 100), from: NSZeroRect, operation: NSCompositingOperation.sourceAtop, fraction: CGFloat.init(1))
  639. //        changeDockImage()
  640.         changeStatusIconImage()
  641.        
  642.     }
  643.     @IBAction func combineImage(_ sender: NSButton) {
  644.  
  645.         let img1 = convertNSimageToCIImage(image: imageDockController.image!)
  646.         let img2 = convertNSimageToCIImage(image: imageStatusController.image!)
  647.  
  648.  
  649.        
  650.         let filter = CIFilter(name: "CIAdditionCompositing")!
  651.         filter.setDefaults()
  652.        
  653.  
  654.        
  655. //        filter.setValue(img1, forKey: "inputImage")
  656.         filter.setValuesForKeys(["inputImage":img1])//,kCIInputWidthKey:img1])
  657.         filter.setValue(img2, forKey: "inputBackgroundImage")
  658.        
  659.         let resultImage = filter.outputImage
  660.        
  661.  
  662.         let rep = NSCIImageRep(ciImage: resultImage!)
  663.         let finalResult = NSImage(size: rep.size)
  664.         finalResult.addRepresentation(rep)
  665.         finalResult.writePNG(toURL: URL(fileURLWithPath: NSHomeDirectory() + "/Desktop/combined.png"))
  666.  
  667.        
  668.        
  669.     }
  670.     @IBOutlet weak var poza1: NSImageView!
  671.     @IBOutlet weak var poza2: NSImageView!
  672.  
  673.     @IBOutlet weak var pozaTestIcon: NSButton!
  674.     @IBOutlet weak var pozaTestICon2: NSButton!
  675.    
  676.     @IBAction func pozaTestIcon(_ sender: NSButton) {
  677.                 colorPick.initFunc()
  678.         colorPick.initFunc()
  679.         if sender == pozaTestIcon {
  680.             pozaTestIcon.state = NSControl.StateValue.on
  681.             pozaTestICon2.state = NSControl.StateValue.off
  682.         } else {
  683.             pozaTestICon2.state = NSControl.StateValue.on
  684.             pozaTestIcon.state = NSControl.StateValue.off
  685.         }
  686.     }
  687.    
  688.        
  689.    
  690. }
  691.    
  692.    
  693.  
  694.  
  695.  
  696.  
  697. //            sender.attributedTitle = NSMutableAttributedString(string: "Hello World", attributes: [NSAttributedStringKey.foregroundColor: NSColor.black, NSAttributedStringKey.paragraphStyle: NSParagraphStyle.default, NSAttributedStringKey.font: NSFont.systemFont(ofSize: 18)])d
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement