Skip to content

Commit

Permalink
Add mark shadow
Browse files Browse the repository at this point in the history
  • Loading branch information
LEOYoon-Tsaw committed Oct 12, 2021
1 parent 3629069 commit 8fd2a11
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 28 deletions.
4 changes: 2 additions & 2 deletions ChineseTime.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 18;
CURRENT_PROJECT_VERSION = 20;
DEVELOPMENT_TEAM = 28HU5A7B46;
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = ChineseTime/Info.plist;
Expand All @@ -327,7 +327,7 @@
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 18;
CURRENT_PROJECT_VERSION = 20;
DEVELOPMENT_TEAM = 28HU5A7B46;
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = ChineseTime/Info.plist;
Expand Down
4 changes: 4 additions & 0 deletions ChineseTime/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import Cocoa
@main
class AppDelegate: NSObject, NSApplicationDelegate {

@IBAction func showHelp(_ sender: Any) {
NSWorkspace.shared.open(URL(string: "https://github.com/LEOYoon-Tsaw/ChineseTime")!)
}

func applicationWillFinishLaunching(_ aNotification: Notification) {
}

Expand Down
2 changes: 1 addition & 1 deletion ChineseTime/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<string>Chinese Time</string>
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
Expand Down
33 changes: 23 additions & 10 deletions ChineseTime/Layout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,8 @@ class GradientSlider: NSControl, NSColorChanging {
}
isLoop = newValue.isLoop
updateLayerFrames()
initializeControls()
updateGradient()
}
}

Expand All @@ -784,12 +786,15 @@ class GradientSlider: NSControl, NSColorChanging {
layer?.addSublayer(trackLayer)
layer?.addSublayer(controlsLayer)
updateLayerFrames()
initializeControls()
updateGradient()
}

override var frame: CGRect {
didSet {
updateLayerFrames()
}
didSet {
updateLayerFrames()
changeChontrols()
}
}

override var acceptsFirstResponder: Bool {
Expand All @@ -811,6 +816,21 @@ class GradientSlider: NSControl, NSColorChanging {
controlsLayer.addSublayer(control)
}

private func initializeControls() {
controlsLayer.sublayers = []
controls = []
for i in 0..<values.count {
addControl(at: values[i], color: colors[i])
}
}

private func changeChontrols() {
for i in 0..<controls.count {
controls[i].path = CGPath(ellipseIn: NSRect(origin: thumbOriginForValue(values[i]), size: NSMakeSize(controlRadius * 2, controlRadius * 2)), transform: nil)
controls[i].shadowPath = controls[i].path
}
}

private func updateLayerFrames() {
trackLayer.frame = bounds.insetBy(dx: bounds.height / 2, dy: bounds.height / 3)
let mask = CAShapeLayer()
Expand All @@ -820,13 +840,6 @@ class GradientSlider: NSControl, NSColorChanging {
controlRadius = bounds.height / 3
trackLayer.startPoint = NSMakePoint(0, 0)
trackLayer.endPoint = NSMakePoint(1, 0)
controlsLayer.sublayers = []
controls = []
for i in 0..<values.count {
addControl(at: values[i], color: colors[i])
}
updateGradient()
trackLayer.setNeedsDisplay()
}

func updateGradient() {
Expand Down
2 changes: 1 addition & 1 deletion ChineseTime/Model.swift
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ class ChineseCalendar {
return monthSplitPositions
}
var fullmoon: [CGFloat] {
_fullMoons.map { CGFloat(_year_start.distance(to: $0) / _year_length) }
_fullMoons.map { CGFloat(_year_start.distance(to: $0) / _year_length) }.filter { ($0 < 1) && ($0 > 0) }
}
var monthNames: [String] {
return _monthNames
Expand Down
14 changes: 12 additions & 2 deletions ChineseTime/WatchFace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -429,10 +429,20 @@ class WatchFaceView: NSView {
func drawMark(at locations: [CGFloat], on ring: RoundedRect, maskPath: CGPath, colors: [NSColor], radius: CGFloat) {
let marks = CALayer()
for i in 0..<locations.count {
let pos = ring.arcPoints(lambdas: [locations[i]]).first!.position
let markPath = CGPath(ellipseIn: NSMakeRect(pos.x - radius, pos.y - radius, 2 * radius, 2 * radius), transform: nil)
let point = ring.arcPoints(lambdas: [locations[i]]).first!
let pos = point.position
let angle = point.direction
var transform = CGAffineTransform(translationX: -pos.x, y: -pos.y)
transform = transform.concatenating(CGAffineTransform(rotationAngle: -angle))
transform = transform.concatenating(CGAffineTransform(translationX: pos.x, y: pos.y))
let markPath: CGPath = RoundedRect(rect: NSMakeRect(pos.x - radius, pos.y - radius, 2 * radius, 2 * radius), nodePos: 0.7 * radius, ankorPos: 0.3 * radius).path
let mark = shapeFrom(path: markPath)
mark.setAffineTransform(transform)
mark.fillColor = colors[i % colors.count].cgColor
mark.shadowPath = mark.path
mark.shadowOffset = NSZeroSize
mark.shadowRadius = radius / 2
mark.shadowOpacity = Float(0.3 * mark.fillColor!.alpha)
marks.addSublayer(mark)
}
let mask = shapeFrom(path: maskPath)
Expand Down
33 changes: 21 additions & 12 deletions ChineseTime/en.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<menu key="submenu" title="Services" systemMenu="services" id="hz9-B4-Xy5"/>
</menuItem>
<menuItem isSeparatorItem="YES" id="4je-JR-u6R"/>
<menuItem title="Hide ChineseTime" keyEquivalent="h" id="Olw-nP-bQN">
<menuItem title="Hide Chinese Time" keyEquivalent="h" id="Olw-nP-bQN">
<connections>
<action selector="hide:" target="Ady-hI-5gd" id="PnN-Uc-m68"/>
</connections>
Expand All @@ -52,7 +52,7 @@
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="kCx-OE-vgT"/>
<menuItem title="Quit ChineseTime" keyEquivalent="q" id="4sb-4s-VLi">
<menuItem title="Quit Chinese Time" keyEquivalent="q" id="4sb-4s-VLi">
<connections>
<action selector="terminate:" target="Ady-hI-5gd" id="Te7-pn-YzF"/>
</connections>
Expand Down Expand Up @@ -665,9 +665,9 @@
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Help" systemMenu="help" id="F2S-fz-NVQ">
<items>
<menuItem title="ChineseTime Help" keyEquivalent="?" id="FKE-Sm-Kum">
<menuItem title="Chinese Time Help" keyEquivalent="?" id="FKE-Sm-Kum">
<connections>
<action selector="showHelp:" target="Ady-hI-5gd" id="y7X-2Q-9no"/>
<action selector="showHelp:" target="Voe-Tx-rLC" id="B5q-CI-xGS"/>
</connections>
</menuItem>
</items>
Expand Down Expand Up @@ -1054,7 +1054,7 @@
</connections>
</popUpButton>
<popUpButton wantsLayer="YES" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Spb-JF-0sa">
<rect key="frame" x="316" y="254" width="141" height="25"/>
<rect key="frame" x="315" y="254" width="142" height="25"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMinY="YES"/>
<popUpButtonCell key="cell" type="push" title="Item 1" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" selectedItem="0Bo-Tc-KcV" id="Haw-mw-Ptu">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
Expand Down Expand Up @@ -1105,7 +1105,7 @@
</connections>
</popUpButton>
<popUpButton wantsLayer="YES" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="OGN-eG-i5S">
<rect key="frame" x="316" y="209" width="141" height="25"/>
<rect key="frame" x="315" y="209" width="142" height="25"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMinY="YES"/>
<popUpButtonCell key="cell" type="push" title="Item 1" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" selectedItem="7kl-LP-siJ" id="kiq-dh-9dK">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
Expand Down Expand Up @@ -1229,8 +1229,8 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
<datePickerCell key="cell" enabled="NO" borderStyle="bezel" alignment="left" drawsBackground="NO" useCurrentDate="YES" id="O3W-Rm-xGz">
<font key="font" metaFont="system"/>
<date key="date" timeIntervalSinceReferenceDate="655532564.297979">
<!--2021-10-10 04:22:44 +0000-->
<date key="date" timeIntervalSinceReferenceDate="655595227.23411">
<!--2021-10-10 21:47:07 +0000-->
</date>
<date key="minDate" timeIntervalSinceReferenceDate="-3124983600">
<!--1901-12-23 05:00:00 +0000-->
Expand Down Expand Up @@ -1313,7 +1313,7 @@
<color key="color" red="0.05813049898" green="0.055541899059999997" blue="1" alpha="1" colorSpace="calibratedRGB"/>
</colorWell>
<switch horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" baseWritingDirection="leftToRight" alignment="left" translatesAutoresizingMaskIntoConstraints="NO" id="LQj-E2-TaW">
<rect key="frame" x="216" y="1064" width="42" height="25"/>
<rect key="frame" x="215" y="1064" width="42" height="25"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES"/>
</switch>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="UrE-IN-zsx">
Expand Down Expand Up @@ -1400,6 +1400,15 @@
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMinY="YES"/>
<color key="color" red="0.05813049898" green="0.055541899059999997" blue="1" alpha="1" colorSpace="calibratedRGB"/>
</colorWell>
<textField wantsLayer="YES" horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="CYx-C6-Rob">
<rect key="frame" x="150" y="20" width="175" height="16"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" lineBreakMode="clipping" enabled="NO" title="Chinese Time by Yuncao Liu" id="aMv-K7-khV">
<font key="font" usesAppearanceFont="YES"/>
<color key="textColor" name="secondaryLabelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
</subviews>
</view>
</subviews>
Expand All @@ -1410,7 +1419,7 @@
<rect key="frame" x="-100" y="-100" width="478" height="16"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
<scroller key="verticalScroller" wantsLayer="YES" verticalHuggingPriority="750" doubleValue="1" horizontal="NO" id="Lmc-Hf-xdD">
<scroller key="verticalScroller" wantsLayer="YES" verticalHuggingPriority="750" doubleValue="0.97304582210242585" horizontal="NO" id="Lmc-Hf-xdD">
<rect key="frame" x="464" y="28" width="16" height="310"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
Expand Down Expand Up @@ -1449,7 +1458,7 @@ DQ
</connections>
</button>
<button wantsLayer="YES" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="PP3-Tk-C3M">
<rect key="frame" x="359" y="10" width="108" height="32"/>
<rect key="frame" x="358" y="10" width="108" height="32"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMaxY="YES"/>
<buttonCell key="cell" type="push" title="確認" bezelStyle="rounded" alignment="center" state="on" borderStyle="border" inset="2" id="gdE-GG-dqq">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
Expand All @@ -1460,7 +1469,7 @@ DQ
</connections>
</button>
<button wantsLayer="YES" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="nBW-qX-9z0">
<rect key="frame" x="128" y="10" width="108" height="32"/>
<rect key="frame" x="127" y="10" width="108" height="32"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMaxY="YES"/>
<buttonCell key="cell" type="push" title="回復" bezelStyle="rounded" alignment="center" state="on" borderStyle="border" inset="2" id="5zZ-P4-UFo">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
Expand Down

0 comments on commit 8fd2a11

Please sign in to comment.