Skip to content

Commit aa6c519

Browse files
committed
Update code
1 parent fbb05a1 commit aa6c519

File tree

5 files changed

+12
-40
lines changed

5 files changed

+12
-40
lines changed

SigGen/swift/AppDelegate.swift

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -47,27 +47,6 @@ class AppDelegate: NSObject, NSApplicationDelegate
4747
{
4848
// Insert code here to initialize your application
4949

50-
// Find a window
51-
if (NSApp.mainWindow != nil)
52-
{
53-
window = NSApp.mainWindow
54-
}
55-
56-
else if (NSApp.keyWindow != nil)
57-
{
58-
window = NSApp.keyWindow
59-
}
60-
61-
else if (NSApp.windows.count > 0)
62-
{
63-
window = NSApp.windows[0]
64-
}
65-
66-
if (window == nil)
67-
{
68-
return
69-
}
70-
7150
window.contentMinSize = NSMakeSize(340, 260)
7251
window.contentAspectRatio = NSMakeSize(340, 260)
7352
window.collectionBehavior.insert(.fullScreenNone)
@@ -91,7 +70,6 @@ class AppDelegate: NSObject, NSApplicationDelegate
9170
scaleView.layerContentsRedrawPolicy = .onSetNeedsDisplay
9271
displayView.layerContentsRedrawPolicy = .onSetNeedsDisplay
9372

94-
9573
let lStack = NSStackView(views: [scaleView, knobView])
9674

9775
let knobHeight = NSLayoutConstraint(item: knobView,

SigGen/swift/DisplayView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ class DisplayView: SigGenView
6060
attribs = [.font: font, .expansion: expansion]
6161
}
6262

63-
let x = NSMinX(rect) + 2
64-
var y = NSMaxY(rect) - textSize - 2
63+
let x = rect.minX + 2
64+
var y = rect.maxY - textSize - 2
6565

6666
// Draw frequency
6767
let freq = String(format: "%1.2fHz", frequency)

SigGen/swift/KnobView.swift

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,26 +112,23 @@ class KnobView: NSControl
112112
path.fill()
113113

114114
// Translate to centre
115-
let centre = AffineTransform(translationByX: NSMidX(dirtyRect),
116-
byY: NSMidY(dirtyRect))
117-
(centre as NSAffineTransform).concat()
115+
let context = NSGraphicsContext.current!
116+
context.cgContext.translateBy(x: dirtyRect.midX, y: dirtyRect.midY)
118117

119118
// Path for indent
120-
let indentSize = NSMaxX(dirtyRect) / 32
119+
let indentSize = dirtyRect.maxX / 32
121120
let indent = NSMakeRect(-indentSize / 2, -indentSize / 2,
122121
indentSize, indentSize)
123122
let indentPath = NSBezierPath(ovalIn: indent)
124123

125124
// Translate for indent
126-
let indentRadius = NSMidY(inset) * 0.8
125+
let indentRadius = inset.midY * 0.8
127126
let x = sin(value * .pi) * indentRadius
128127
let y = cos(value * .pi) * indentRadius
129-
let transform = AffineTransform(translationByX: x, byY: y)
130-
// (transform as NSAffineTransform).concat()
131-
indentPath.transform(using: transform)
128+
let translate = AffineTransform(translationByX: x, byY: y)
129+
indentPath.translate(using: transform)
132130

133131
// Draw indent
134132
gradient.draw(in: indentPath, angle: 135)
135133
}
136-
137134
}

SigGen/swift/ScaleView.swift

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ class ScaleView: SigGenView
4040

4141
let kTextSize = height / 3
4242
let kFreqScale = width
43-
let context = NSGraphicsContext.current!
4443

4544
let font = NSFont.systemFont(ofSize: kTextSize)
4645
var attribs: [NSAttributedString.Key: Any] = [.font: font]
@@ -55,10 +54,8 @@ class ScaleView: SigGenView
5554

5655
// Drawing code here.
5756
NSEraseRect(rect)
58-
59-
let transform = AffineTransform(translationByX: NSMidX(rect),
60-
byY: NSMidY(rect))
61-
(transform as NSAffineTransform).concat()
57+
let context = NSGraphicsContext.current!
58+
context.cgContext.translateBy(x: rect.midX, y: rect.midY)
6259

6360
let a = [1, 2, 3, 4, 6, 8]
6461
for i in a

SigGen/swift/SigGenView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ class SigGenView: NSView
3434

3535
// Drawing code here.
3636
rect = DrawEdge(dirtyRect)
37-
width = NSWidth(rect)
38-
height = NSHeight(rect)
37+
width = rect.width
38+
height = rect.height
3939
}
4040

4141
// DrawEdge

0 commit comments

Comments
 (0)