Skip to content

Commit

Permalink
update gradient view
Browse files Browse the repository at this point in the history
  • Loading branch information
kyleduo committed May 22, 2017
1 parent 314cbf9 commit 8f06f1e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
4 changes: 4 additions & 0 deletions source/tinypng4mac.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
1D843D7CE0609BA7B4F65DB9 /* Pods_TinyPNG4Mac.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 811CF203124A83759CC63BFF /* Pods_TinyPNG4Mac.framework */; };
272AC1AD1ED2BA5C0005E7D5 /* MainViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27A949CA1D2C02BA0043DECE /* MainViewController.swift */; };
272AC1AF1ED335470005E7D5 /* GradientView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 272AC1AE1ED335470005E7D5 /* GradientView.swift */; };
272C50A01D2D545300EEECC2 /* SpinnerProgressIndicator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 272C509F1D2D545300EEECC2 /* SpinnerProgressIndicator.swift */; };
272C50AD1D2EB03100EEECC2 /* InputKeyAlert.swift in Sources */ = {isa = PBXBuildFile; fileRef = 272C50AC1D2EB03100EEECC2 /* InputKeyAlert.swift */; };
2730E9011D3680A80030A459 /* Credits.rtf in Resources */ = {isa = PBXBuildFile; fileRef = 2730E9001D3680A80030A459 /* Credits.rtf */; };
Expand All @@ -29,6 +30,7 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
272AC1AE1ED335470005E7D5 /* GradientView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GradientView.swift; sourceTree = "<group>"; };
272C509F1D2D545300EEECC2 /* SpinnerProgressIndicator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SpinnerProgressIndicator.swift; sourceTree = "<group>"; };
272C50AC1D2EB03100EEECC2 /* InputKeyAlert.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InputKeyAlert.swift; sourceTree = "<group>"; };
2730E9001D3680A80030A459 /* Credits.rtf */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.rtf; path = Credits.rtf; sourceTree = "<group>"; };
Expand Down Expand Up @@ -130,6 +132,7 @@
277AAF611D250DD100788F37 /* DragContainer.swift */,
272C509F1D2D545300EEECC2 /* SpinnerProgressIndicator.swift */,
272C50AC1D2EB03100EEECC2 /* InputKeyAlert.swift */,
272AC1AE1ED335470005E7D5 /* GradientView.swift */,
);
path = views;
sourceTree = "<group>";
Expand Down Expand Up @@ -288,6 +291,7 @@
files = (
272C50AD1D2EB03100EEECC2 /* InputKeyAlert.swift in Sources */,
272C50A01D2D545300EEECC2 /* SpinnerProgressIndicator.swift in Sources */,
272AC1AF1ED335470005E7D5 /* GradientView.swift in Sources */,
277AAF711D26478A00788F37 /* TaskTableCell.swift in Sources */,
27A949C81D2C00120043DECE /* MainWindowController.swift in Sources */,
277AAF641D25201900788F37 /* TPClient.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion source/tinypng4mac/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@
<constraint firstItem="zRv-TO-bMw" firstAttribute="centerY" secondItem="NnK-w1-6b9" secondAttribute="centerY" id="vhH-ld-Iyv"/>
</constraints>
</visualEffectView>
<view wantsLayer="YES" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="F5f-sg-JvA">
<view wantsLayer="YES" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="F5f-sg-JvA" customClass="GradientView" customModule="TinyPNG4Mac" customModuleProvider="target">
<rect key="frame" x="0.0" y="97" width="320" height="320"/>
<constraints>
<constraint firstAttribute="width" constant="320" id="TZi-1T-Q24"/>
Expand Down
11 changes: 1 addition & 10 deletions source/tinypng4mac/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class MainViewController: NSViewController, NSOpenSavePanelDelegate, NSTableView
@IBOutlet weak var replaceSwitch: NSButton!
@IBOutlet weak var icon: NSImageView!
@IBOutlet weak var desc: NSTextField!
@IBOutlet weak var background: NSView!
@IBOutlet weak var background: GradientView!

var totalSize: Double = 0
var totalRecudeSize: Double = 0
Expand All @@ -41,15 +41,6 @@ class MainViewController: NSViewController, NSOpenSavePanelDelegate, NSTableView
TPClient.sOutputPath = savedPath
}

let bg = CAGradientLayer()
bg.colors = [NSColor(deviceRed:0.08, green:0.66, blue:0.84, alpha:1.00).cgColor, NSColor(deviceRed:0.05, green:0.47, blue:0.73, alpha:1.00).cgColor]
bg.locations = [NSNumber(value: 0), NSNumber(value: 1)]
bg.startPoint = CGPoint(x: 0.5, y: 1)
bg.endPoint = CGPoint(x: 0.5, y: 0)
bg.frame = CGRect(x:0, y:0, width:320, height:320)
background.layer = bg
background.wantsLayer = true

totalReduce.stringValue = NSLocalizedString("0 tasks", comment: "0 tasks")
replaceSwitch.state = TPConfig.shouldReplace() ? NSOnState : NSOffState

Expand Down
19 changes: 19 additions & 0 deletions source/tinypng4mac/views/GradientView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// GradientView.swift
// tinypng4mac
//
// Created by kyle on 2017/5/22.
// Copyright © 2017年 kyleduo. All rights reserved.
//

import Cocoa

class GradientView: NSView {
override func draw(_ dirtyRect: NSRect) {
let path = NSBezierPath()
path.appendRect(dirtyRect)

let gradient = NSGradient(colors: [NSColor(deviceRed:0.08, green:0.66, blue:0.84, alpha:1.00), NSColor(deviceRed:0.05, green:0.47, blue:0.73, alpha:1.00)], atLocations: [0, 1], colorSpace: NSColorSpace.deviceRGB)
gradient?.draw(in: path, angle: -90)
}
}

0 comments on commit 8f06f1e

Please sign in to comment.