Skip to content

Commit

Permalink
Merge pull request #6 from mulot/developpement
Browse files Browse the repository at this point in the history
Developpement
  • Loading branch information
mulot authored Nov 27, 2022
2 parents 4d12c16 + bb3a9c1 commit d9ea267
Show file tree
Hide file tree
Showing 16 changed files with 556 additions and 75 deletions.
210 changes: 193 additions & 17 deletions BeatTime.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>BeatTimeMenuBar.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>9</integer>
<integer>10</integer>
</dict>
<key>BeatTimeTvOS.xcscheme_^#shared#^_</key>
<dict>
Expand Down Expand Up @@ -49,6 +49,11 @@
<key>orderHint</key>
<integer>6</integer>
</dict>
<key>BeatTimeWidgetWatchOSExtension.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>9</integer>
</dict>
<key>BeatTimeWidgetiOSExtension.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
Expand All @@ -62,6 +67,26 @@
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>94196330292ED5FE009BC68A</key>
<dict>
<key>primary</key>
<true/>
</dict>
<key>947C5629264814E9007E6B4A</key>
<dict>
<key>primary</key>
<true/>
</dict>
<key>947C562C264814E9007E6B4A</key>
<dict>
<key>primary</key>
<true/>
</dict>
<key>94BEB1B92646D9C500A5D811</key>
<dict>
<key>primary</key>
<true/>
</dict>
<key>94CBA0C3265308370032CA8B</key>
<dict>
<key>primary</key>
Expand Down
14 changes: 14 additions & 0 deletions BeatTime/BeatTime.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,18 @@ class BeatTime: NSObject {
}
return(Date())
}

/// Return the difference between LocalTimeZone and GMT
/// - Parameter date: local date
/// - Returns: Difference in hours (negative or positive)
static func hoursOffsetWithGMT(date: Date = Date()) -> Int
{
//print(TimeZone.current.identifier)
//print(TimeZone.abbreviationDictionary)
//let seconds = TimeZone.init(identifier: "JST")!.secondsFromGMT(for: date)
let seconds = TimeZone.current.secondsFromGMT(for: date)
let hours = seconds / 3600
//print("seconds: \(seconds) hours: \(hours)")
return(hours)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"images" : [
{
"idiom" : "universal",
"platform" : "watchos",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
6 changes: 6 additions & 0 deletions BeatTimeWidgetWatchOS/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
11 changes: 11 additions & 0 deletions BeatTimeWidgetWatchOS/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSExtension</key>
<dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.widgetkit-extension</string>
</dict>
</dict>
</plist>
3 changes: 3 additions & 0 deletions MacOS/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class AppDelegate: NSObject, NSWindowDelegate, NSApplicationDelegate {
var circleView: RingProgressView!
var isCentiBeats: Bool = false
var statusItem: NSStatusItem?
var lineWidth: CGFloat = 25

@IBAction func changeCentiBeats(_ sender: AnyObject) {
if (beat != nil) {
Expand All @@ -45,6 +46,7 @@ class AppDelegate: NSObject, NSWindowDelegate, NSApplicationDelegate {
circle.arcFrag = 1000
circle.lineColor = NSColor.gray.cgColor
circle.isShadow = true
circle.lineWidth = lineWidth
if (circleView != nil) {
view.replaceSubview(circleView, with: circle)
circleView = circle
Expand All @@ -57,6 +59,7 @@ class AppDelegate: NSObject, NSWindowDelegate, NSApplicationDelegate {
let circleBeat = RingProgressView(frame: NSRect(x: window.contentLayoutRect.width/2 - (circleDiameter/2), y: window.contentLayoutRect.height/2 - (circleDiameter/2), width: circleDiameter, height: circleDiameter))
if (beat != nil) {
circleBeat.arcFrag = Double(beat.beats()) ?? 0
circleBeat.lineWidth = lineWidth
//circleBeat.arcFrag = 999 // TEST FULL CIRCLE
}
if (circleBeatView != nil) {
Expand Down
11 changes: 9 additions & 2 deletions TvOS/BeatTimeTvOSApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,15 @@ struct ContentView: View {
.font(.title.bold())
.gradientForeground(colors: [.startGradient, .midGradient, .mid2Gradient, .endGradient])
*/
BeatTimeView(lineWidth: 40)

if #available(tvOS 16.0, *) {
BeatTimeView(lineWidth: 40)
.onTapGesture {
print("Tap")
}
}
else {
BeatTimeView(lineWidth: 40)
}
}
}
}
Expand Down
20 changes: 4 additions & 16 deletions View/BeatTImeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct BeatTimeView: View {
}
if (Double(beats) != nil) {
RingProgressView(arcFrag: Double(beats)!, lineWidth: lineWidth)
.gradientForeground(colors: [.startGradient, .midGradient, .mid2Gradient, .endGradient], startPoint: startGradient, endPoint: endGradient)
.gradientLinear(colors: [.startGradient, .midGradient, .mid2Gradient, .endGradient], startPoint: startGradient, endPoint: endGradient)
.onAppear() {
withAnimation(.default.speed(0.30)) {
//print("animation on Appear")
Expand Down Expand Up @@ -60,7 +60,7 @@ struct BeatTimeView: View {
#endif*/
}
TextFitView(text: "@" + beats, size: displayLenght)
.gradientForeground(colors: [.startGradient, .midGradient, .mid2Gradient, .endGradient])
.gradientLinear(colors: [.startGradient, .midGradient, .mid2Gradient, .endGradient])
/*Text("@" + beats)
.font(.largeTitle.bold())
.font(.system(size: fontSize, weight: .bold))*/
Expand All @@ -86,8 +86,8 @@ struct BeatTimeView: View {

func gradientPosition(date: Date = Date(), frame: CGRect, lenght: CGFloat, followSun: Bool = true) -> (UnitPoint, UnitPoint)
{
let nbHour = hoursOffsetWithGMT()
let angle = (2 * Double.pi) / 24 * Double(nbHour)
let nbHour = BeatTime.hoursOffsetWithGMT()
let angle = -(2 * Double.pi) / 24 * Double(nbHour)
let r = lenght / 2
let startCircle = UnitPoint(x: 0.5, y: (1 - (lenght / frame.height)) / 2)
let endCircle = UnitPoint(x: 0.5, y: 1 - ((1 - (lenght / frame.height)) / 2))
Expand All @@ -105,18 +105,6 @@ struct BeatTimeView: View {
return (startCircle, endCircle)
}
}


func hoursOffsetWithGMT(date: Date = Date()) -> Int
{
//print(TimeZone.current.identifier)
//print(TimeZone.abbreviationDictionary)
//let seconds = TimeZone.init(identifier: "JST")!.secondsFromGMT(for: date)
let seconds = TimeZone.current.secondsFromGMT(for: date)
let hours = seconds / 3600
//print("seconds: \(seconds) hours: \(-hours)")
return(-hours)
}
}

struct BeatTime_Previews: PreviewProvider {
Expand Down
6 changes: 3 additions & 3 deletions View/Colors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import SwiftUI
extension Color {
static let timeLine = Color.orange
static let circleLine = Color(red: 230/255, green: 230/255, blue: 230/255)
static let startGradient = Color(red: 0, green: 30/255, blue: 50/255)
static let startGradient = Color(red: 0, green: 30/255, blue: 50/255) // midnight
static let midGradient = Color.purple
static let mid2Gradient = Color(red: 247/255, green: 186/255, blue: 0)
static let endGradient = Color(red: 1, green: 1, blue: 0)
static let mid2Gradient = Color(red: 247/255, green: 186/255, blue: 0) // neaar orange
static let endGradient = Color(red: 1, green: 1, blue: 0) // yellow
}
13 changes: 9 additions & 4 deletions View/UIViewDraw.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@
import SwiftUI

extension View {
public func gradientForeground(colors: [Color], startPoint: UnitPoint = .top, endPoint: UnitPoint = .bottom) -> some View {
self.overlay(LinearGradient(gradient: .init(colors: colors),
startPoint: startPoint,
endPoint: endPoint))
public func gradientLinear(colors: [Color], startPoint: UnitPoint = .top, endPoint: UnitPoint = .bottom) -> some View {
self.overlay(LinearGradient(gradient: .init(colors: colors),
startPoint: startPoint,
endPoint: endPoint))
.mask(self)
}
public func gradientRadius(colors: [Color], center: UnitPoint = .center, startRadius: CGFloat = 0, endRadius: CGFloat = 1) -> some View {
self.overlay(RadialGradient(gradient: .init(colors: colors),
center: center, startRadius: startRadius, endRadius: endRadius))
.mask(self)
}
}

struct RingProgressView: Shape {
Expand Down
6 changes: 4 additions & 2 deletions WatchOS WatchKit Extension/BeatTimeApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -174,18 +174,20 @@ struct ContentView: View {
*/
ProgressView(value: Double(beats)!/1000)
.progressViewStyle(CircularProgressViewStyle(tint: fgColors[Int(index.rounded())]))
//.scaledToFit()
//.gradientLinear(colors: [.startGradient, .midGradient, .mid2Gradient, .endGradient])
//.scaledToFit()
.frame(width: frame.width, height: frame.height, alignment: .center)
.scaleEffect(3.2, anchor: .center)
.onAppear() {
withAnimation(.default.speed(0.25)) {
self.beats = BeatTime().beats()
print("animation on Appear")
//print("animation on Appear")
}
}
Text("@" + beats)
.font(.title.bold())
.foregroundColor(fgColors[Int(index.rounded())])
//.gradientLinear(colors: [.startGradient, .midGradient, .mid2Gradient, .endGradient])
//Text("Index : \(index)")
}
.focusable()
Expand Down
Loading

0 comments on commit d9ea267

Please sign in to comment.