Skip to content

Commit

Permalink
Added repeated actions for center sixths actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Hanson committed Sep 26, 2020
1 parent 2686aa5 commit 22e5060
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 14 deletions.
20 changes: 19 additions & 1 deletion Rectangle/WindowAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,17 @@ enum SubWindowAction {
leftCenterSixthPortrait,
rightCenterSixthPortrait,
bottomLeftSixthPortrait,
bottomRightSixthPortrait
bottomRightSixthPortrait,

topLeftTwoSixthsLandscape,
topLeftTwoSixthsPortrait,
topRightTwoSixthsLandscape,
topRightTwoSixthsPortrait,

bottomLeftTwoSixthsLandscape,
bottomLeftTwoSixthsPortrait,
bottomRightTwoSixthsLandscape,
bottomRightTwoSixthsPortrait

var gapSharedEdge: Edge {
switch self {
Expand Down Expand Up @@ -463,6 +473,14 @@ enum SubWindowAction {
case .rightCenterSixthPortrait: return [.left, .top, .bottom]
case .bottomLeftSixthPortrait: return [.top, .right]
case .bottomRightSixthPortrait: return [.left, .top]
case .topLeftTwoSixthsLandscape: return [.right, .bottom]
case .topLeftTwoSixthsPortrait: return [.right, .bottom]
case .topRightTwoSixthsLandscape: return [.left, .bottom]
case .topRightTwoSixthsPortrait: return [.left, .bottom]
case .bottomLeftTwoSixthsLandscape: return [.right, .top]
case .bottomLeftTwoSixthsPortrait: return [.right, .top]
case .bottomRightTwoSixthsLandscape: return [.left, .top]
case .bottomRightTwoSixthsPortrait: return [.left, .top]
}
}
}
Expand Down
55 changes: 53 additions & 2 deletions Rectangle/WindowCalculation/BottomCenterSixthCalculation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,28 @@ import Foundation

class BottomCenterSixthCalculation: WindowCalculation, OrientationAware {

private let bottomRightTwoSixths = BottomRightTwoSixthsCalculation()
private let bottomLeftTwoSixths = BottomLeftTwoSixthsCalculation()

override func calculateRect(_ window: Window, lastAction: RectangleAction?, visibleFrameOfScreen: CGRect, action: WindowAction) -> RectResult {
guard Defaults.subsequentExecutionMode.value != .none,
let last = lastAction, let lastSubAction = last.subAction else {
let last = lastAction,
let lastSubAction = last.subAction,
action == .bottomCenterSixth
else {
return orientationBasedRect(visibleFrameOfScreen)
}

return orientationBasedRect(visibleFrameOfScreen)
let calc: SimpleCalc
switch lastSubAction{
case .bottomCenterSixthLandscape, .rightCenterSixthPortrait:
calc = bottomRightTwoSixths.orientationBasedRect
case .bottomRightTwoSixthsLandscape, .bottomRightTwoSixthsPortrait:
calc = bottomLeftTwoSixths.orientationBasedRect
default: calc = orientationBasedRect
}

return calc(visibleFrameOfScreen)
}

func landscapeRect(_ visibleFrameOfScreen: CGRect) -> RectResult {
Expand All @@ -36,3 +51,39 @@ class BottomCenterSixthCalculation: WindowCalculation, OrientationAware {
return RectResult(rect, subAction: .rightCenterSixthPortrait)
}
}

class BottomRightTwoSixthsCalculation: WindowCalculation, OrientationAware {

func landscapeRect(_ visibleFrameOfScreen: CGRect) -> RectResult {
var rect = visibleFrameOfScreen
rect.size.width = floor(visibleFrameOfScreen.width * 2.0 / 3.0)
rect.size.height = floor(visibleFrameOfScreen.height / 2.0)
rect.origin.x = visibleFrameOfScreen.maxX - rect.width
return RectResult(rect, subAction: .bottomRightTwoSixthsLandscape)
}

func portraitRect(_ visibleFrameOfScreen: CGRect) -> RectResult {
var rect = visibleFrameOfScreen
rect.size.width = floor(visibleFrameOfScreen.width / 2.0)
rect.size.height = floor(visibleFrameOfScreen.height * 2.0 / 3.0)
rect.origin.x = visibleFrameOfScreen.maxX - rect.width
return RectResult(rect, subAction: .bottomRightTwoSixthsPortrait)
}
}

class BottomLeftTwoSixthsCalculation: WindowCalculation, OrientationAware {

func landscapeRect(_ visibleFrameOfScreen: CGRect) -> RectResult {
var rect = visibleFrameOfScreen
rect.size.width = floor(visibleFrameOfScreen.width * 2.0 / 3.0)
rect.size.height = floor(visibleFrameOfScreen.height / 2.0)
return RectResult(rect, subAction: .bottomLeftTwoSixthsLandscape)
}

func portraitRect(_ visibleFrameOfScreen: CGRect) -> RectResult {
var rect = visibleFrameOfScreen
rect.size.width = floor(visibleFrameOfScreen.width / 2.0)
rect.size.height = floor(visibleFrameOfScreen.height * 2.0 / 3.0)
return RectResult(rect, subAction: .bottomLeftTwoSixthsPortrait)
}
}
5 changes: 2 additions & 3 deletions Rectangle/WindowCalculation/SecondFourthCalculation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import Foundation
class SecondFourthCalculation: WindowCalculation, OrientationAware {

let threeFourthsCalculation = RightOrBottomThreeFourthsCalculation()
let centerHalfCalculation = CenterHalfCalculation()

override func calculateRect(_ window: Window, lastAction: RectangleAction?, visibleFrameOfScreen: CGRect, action: WindowAction) -> RectResult {

Expand All @@ -30,9 +29,9 @@ class SecondFourthCalculation: WindowCalculation, OrientationAware {
case .centerTopFourth:
calc = threeFourthsCalculation.portraitRect
case .rightThreeFourths:
calc = centerHalfCalculation.landscapeRect
calc = WindowCalculationFactory.centerHalfCalculation.landscapeRect
case .bottomThreeFourths:
calc = centerHalfCalculation.portraitRect
calc = WindowCalculationFactory.centerHalfCalculation.portraitRect
default:
calc = orientationBasedRect
}
Expand Down
5 changes: 2 additions & 3 deletions Rectangle/WindowCalculation/ThirdFourthCalculation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import Foundation
class ThirdFourthCalculation: WindowCalculation, OrientationAware {

let threeFourthsCalculation = LeftOrTopThreeFourthsCalculation()
let centerHalfCalculation = CenterHalfCalculation()

override func calculateRect(_ window: Window, lastAction: RectangleAction?, visibleFrameOfScreen: CGRect, action: WindowAction) -> RectResult {
guard Defaults.subsequentExecutionMode.value != .none,
Expand All @@ -29,9 +28,9 @@ class ThirdFourthCalculation: WindowCalculation, OrientationAware {
case .centerBottomFourth:
calc = threeFourthsCalculation.portraitRect
case .leftThreeFourths:
calc = centerHalfCalculation.landscapeRect
calc = WindowCalculationFactory.centerHalfCalculation.landscapeRect
case .topThreeFourths:
calc = centerHalfCalculation.portraitRect
calc = WindowCalculationFactory.centerHalfCalculation.portraitRect
default:
calc = orientationBasedRect
}
Expand Down
63 changes: 58 additions & 5 deletions Rectangle/WindowCalculation/TopCenterSixthCalculation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,82 @@ import Foundation

class TopCenterSixthCalculation: WindowCalculation, OrientationAware {

private let topRightTwoSixths = TopRightTwoSixthsCalculation()
private let topLeftTwoSixths = TopLeftTwoSixthsCalculation()

override func calculateRect(_ window: Window, lastAction: RectangleAction?, visibleFrameOfScreen: CGRect, action: WindowAction) -> RectResult {
guard Defaults.subsequentExecutionMode.value != .none,
let last = lastAction, let lastSubAction = last.subAction else {
let last = lastAction,
let lastSubAction = last.subAction,
action == .topCenterSixth
else {
return orientationBasedRect(visibleFrameOfScreen)
}

return orientationBasedRect(visibleFrameOfScreen)
let calc: SimpleCalc
switch lastSubAction{
case .topCenterSixthLandscape, .leftCenterSixthPortrait:
calc = topRightTwoSixths.orientationBasedRect
case .topRightTwoSixthsLandscape, .topRightTwoSixthsPortrait:
calc = topLeftTwoSixths.orientationBasedRect
default: calc = orientationBasedRect
}

return calc(visibleFrameOfScreen)
}

func landscapeRect(_ visibleFrameOfScreen: CGRect) -> RectResult {
var rect = visibleFrameOfScreen
rect.size.width = floor(visibleFrameOfScreen.width / 3.0)
rect.size.height = floor(visibleFrameOfScreen.height / 2.0)
rect.origin.x = visibleFrameOfScreen.origin.x + rect.width
rect.origin.y = visibleFrameOfScreen.origin.y + rect.height
rect.origin.x = visibleFrameOfScreen.minX + rect.width
rect.origin.y = visibleFrameOfScreen.minY + rect.height
return RectResult(rect, subAction: .topCenterSixthLandscape)
}

func portraitRect(_ visibleFrameOfScreen: CGRect) -> RectResult {
var rect = visibleFrameOfScreen
rect.size.width = floor(visibleFrameOfScreen.width / 2.0)
rect.size.height = floor(visibleFrameOfScreen.height / 3.0)
rect.origin.y = visibleFrameOfScreen.origin.y + rect.height
rect.origin.y = visibleFrameOfScreen.minY + rect.height
return RectResult(rect, subAction: .leftCenterSixthPortrait)
}
}

class TopRightTwoSixthsCalculation: WindowCalculation, OrientationAware {

func landscapeRect(_ visibleFrameOfScreen: CGRect) -> RectResult {
var rect = visibleFrameOfScreen
rect.size.width = floor(visibleFrameOfScreen.width * 2.0 / 3.0)
rect.size.height = floor(visibleFrameOfScreen.height / 2.0)
rect.origin.x = visibleFrameOfScreen.maxX - rect.width
rect.origin.y = visibleFrameOfScreen.minY + rect.height
return RectResult(rect, subAction: .topRightTwoSixthsLandscape)
}

func portraitRect(_ visibleFrameOfScreen: CGRect) -> RectResult {
var rect = visibleFrameOfScreen
rect.size.width = floor(visibleFrameOfScreen.width / 2.0)
rect.size.height = floor(visibleFrameOfScreen.height * 2.0 / 3.0)
return RectResult(rect, subAction: .topRightTwoSixthsPortrait)
}
}

class TopLeftTwoSixthsCalculation: WindowCalculation, OrientationAware {

func landscapeRect(_ visibleFrameOfScreen: CGRect) -> RectResult {
var rect = visibleFrameOfScreen
rect.size.width = floor(visibleFrameOfScreen.width * 2.0 / 3.0)
rect.size.height = floor(visibleFrameOfScreen.height / 2.0)
rect.origin.y = visibleFrameOfScreen.minY + rect.height
return RectResult(rect, subAction: .topLeftTwoSixthsLandscape)
}

func portraitRect(_ visibleFrameOfScreen: CGRect) -> RectResult {
var rect = visibleFrameOfScreen
rect.size.width = floor(visibleFrameOfScreen.width / 2.0)
rect.size.height = floor(visibleFrameOfScreen.height * 2.0 / 3.0)
rect.origin.y = visibleFrameOfScreen.minY + rect.height
return RectResult(rect, subAction: .topLeftTwoSixthsPortrait)
}
}

0 comments on commit 22e5060

Please sign in to comment.