Skip to content

Commit

Permalink
Add checkerboard background for the trim view (#140)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
  • Loading branch information
SergeyKuryanov and sindresorhus committed Oct 8, 2019
1 parent 1a8f426 commit 91dd426
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Gifski.xcodeproj/project.pbxproj
Expand Up @@ -22,6 +22,7 @@
B576D25422294F9900A9B75C /* CircularProgress+Util.swift in Sources */ = {isa = PBXBuildFile; fileRef = B576D24F22294F9900A9B75C /* CircularProgress+Util.swift */; };
C2040B8920435871004EE259 /* GifskiWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = C2040B8820435871004EE259 /* GifskiWrapper.swift */; };
C2AFA91D204FFEFD00FC5A7F /* MainWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C2AFA91B204FFEFD00FC5A7F /* MainWindowController.swift */; };
D957BCDE234941C200A9A9F9 /* CheckerboardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D957BCDD234941C200A9A9F9 /* CheckerboardView.swift */; };
E3030388233785C100B8ED1F /* CustomButton+Util.swift in Sources */ = {isa = PBXBuildFile; fileRef = E3030387233785C100B8ED1F /* CustomButton+Util.swift */; };
E30557F0207E521F003401A1 /* Defaults.swift in Sources */ = {isa = PBXBuildFile; fileRef = E30557EF207E521F003401A1 /* Defaults.swift */; };
E317FF132057E24700A80A18 /* CircularProgress.swift in Sources */ = {isa = PBXBuildFile; fileRef = E317FF122057E24700A80A18 /* CircularProgress.swift */; };
Expand Down Expand Up @@ -98,6 +99,7 @@
B576D24F22294F9900A9B75C /* CircularProgress+Util.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = "CircularProgress+Util.swift"; sourceTree = "<group>"; usesTabs = 1; };
C2040B8820435871004EE259 /* GifskiWrapper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = GifskiWrapper.swift; sourceTree = "<group>"; usesTabs = 1; };
C2AFA91B204FFEFD00FC5A7F /* MainWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = MainWindowController.swift; sourceTree = "<group>"; usesTabs = 1; };
D957BCDD234941C200A9A9F9 /* CheckerboardView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = CheckerboardView.swift; sourceTree = "<group>"; usesTabs = 1; };
E3030387233785C100B8ED1F /* CustomButton+Util.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = "CustomButton+Util.swift"; sourceTree = "<group>"; usesTabs = 1; };
E30557EF207E521F003401A1 /* Defaults.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Defaults.swift; sourceTree = "<group>"; };
E317FF122057E24700A80A18 /* CircularProgress.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CircularProgress.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -220,6 +222,7 @@
9F3340A222431CC3006EF9B5 /* TimeRemainingEstimator.swift */,
E339F010203820ED003B78FB /* Gifski.swift */,
C2040B8820435871004EE259 /* GifskiWrapper.swift */,
D957BCDD234941C200A9A9F9 /* CheckerboardView.swift */,
8588EB0C22A424B800030A59 /* ResizableDimensions.swift */,
8548806422B78E8300E97401 /* IntTextField.swift */,
8548806D22B82D1300E97401 /* MenuPopUpButton.swift */,
Expand Down Expand Up @@ -397,6 +400,7 @@
E3A6BD112245345C00F62256 /* Constants.swift in Sources */,
C2040B8920435871004EE259 /* GifskiWrapper.swift in Sources */,
8588EB0D22A424B800030A59 /* ResizableDimensions.swift in Sources */,
D957BCDE234941C200A9A9F9 /* CheckerboardView.swift in Sources */,
858380EA22BFD38C0086BC98 /* ExtendedAttributes.swift in Sources */,
E3030388233785C100B8ED1F /* CustomButton+Util.swift in Sources */,
E3CB1DD71F7E4CBC00D79BFC /* VideoDropView.swift in Sources */,
Expand Down
@@ -0,0 +1,38 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
},
"colors" : [
{
"idiom" : "universal",
"color" : {
"color-space" : "srgb",
"components" : {
"red" : "1.000",
"alpha" : "1.000",
"blue" : "1.000",
"green" : "1.000"
}
}
},
{
"idiom" : "universal",
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "srgb",
"components" : {
"red" : "0.261",
"alpha" : "1.000",
"blue" : "0.261",
"green" : "0.261"
}
}
}
]
}
@@ -0,0 +1,38 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
},
"colors" : [
{
"idiom" : "universal",
"color" : {
"color-space" : "srgb",
"components" : {
"red" : "209",
"alpha" : "1.000",
"blue" : "209",
"green" : "209"
}
}
},
{
"idiom" : "universal",
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "srgb",
"components" : {
"red" : "0x83",
"alpha" : "1.000",
"blue" : "0x85",
"green" : "0x84"
}
}
}
]
}
37 changes: 37 additions & 0 deletions Gifski/CheckerboardView.swift
@@ -0,0 +1,37 @@
import Cocoa

final class CheckerboardView: NSView {
private let gridSize = CGSize(width: 8, height: 8)
private let clearRect: CGRect

init(frame: CGRect, clearRect: CGRect) {
self.clearRect = clearRect

super.init(frame: frame)
}

required init?(coder: NSCoder) {
self.clearRect = .zero

super.init(coder: coder)
}

override func draw(_ dirtyRect: CGRect) {
super.draw(dirtyRect)

NSColor.Checkerboard.first.setFill()
dirtyRect.fill()

NSColor.Checkerboard.second.setFill()

for y in 0...Int(bounds.size.height / gridSize.height) {
for x in 0...Int(bounds.size.width / gridSize.width) where x.isEven == y.isEven {
let origin = CGPoint(x: x * Int(gridSize.width), y: y * Int(gridSize.height))
let rect = CGRect(origin: origin, size: gridSize)
rect.fill()
}
}

clearRect.fill(using: .clear)
}
}
5 changes: 5 additions & 0 deletions Gifski/Constants.swift
Expand Up @@ -2,6 +2,11 @@ import Cocoa

extension NSColor {
static let themeColor = NSColor.controlAccentColorPolyfill

enum Checkerboard {
static let first = NSColor(named: "CheckerboardFirstColor")!
static let second = NSColor(named: "CheckerboardSecondColor")!
}
}

extension Defaults.Keys {
Expand Down
6 changes: 6 additions & 0 deletions Gifski/TrimmingAVPlayerViewController.swift
Expand Up @@ -44,6 +44,7 @@ final class TrimmingAVPlayerViewController: NSViewController {
override func viewDidAppear() {
super.viewDidAppear()

playerView.addCheckerboardView()
playerView.hideTrimButtons()
playerView.observeTrimmedTimeRange { [weak self] timeRange in
self?.timeRange = timeRange
Expand Down Expand Up @@ -131,4 +132,9 @@ final class TrimmingAVPlayerView: AVPlayerView {
.filter { ($0 as? NSButton)?.image == nil }
.forEach { $0.isHidden = true }
}

fileprivate func addCheckerboardView() {
let overlayView = CheckerboardView(frame: frame, clearRect: videoBounds)
contentOverlayView?.addSubview(overlayView)
}
}
5 changes: 5 additions & 0 deletions Gifski/util.swift
Expand Up @@ -2574,3 +2574,8 @@ extension ClosedRange where Bound == Double {
return self
}
}

extension BinaryInteger {
var isEven: Bool { isMultiple(of: 2) }
var isOdd: Bool { !isEven }
}

0 comments on commit 91dd426

Please sign in to comment.