Skip to content

Commit e857d4a

Browse files
committed
Update code
1 parent 9f9cb33 commit e857d4a

File tree

3 files changed

+35
-35
lines changed

3 files changed

+35
-35
lines changed

Scope/swift/ScopeView.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ class ScopeView: NSView
9696
super.draw(rect)
9797

9898
// Drawing code here.
99-
let width = NSWidth(rect)
100-
let height = NSHeight(rect)
99+
let width = rect.width
100+
let height = rect.height
101101

102102
let context = NSGraphicsContext.current!
103103

@@ -134,23 +134,23 @@ class ScopeView: NSView
134134
graticule.setStrokeColor(darkGreen)
135135

136136
// Move the origin
137-
graticule.translateBy(x: 0, y: NSMidY(rect))
137+
graticule.translateBy(x: 0, y: rect.midY)
138138
graticule.setShouldAntialias(false)
139139

140140
// Draw graticule
141141
graticule.beginPath()
142-
for x in stride(from: 0, to: NSWidth(rect), by: 10)
142+
for x in stride(from: 0, to: rect.width, by: 10)
143143
{
144-
graticule.move(to: NSMakePoint(x, NSMaxY(rect) / 2))
145-
graticule.addLine(to: NSMakePoint(x, -NSMaxY(rect) / 2))
144+
graticule.move(to: NSMakePoint(x, rect.maxY / 2))
145+
graticule.addLine(to: NSMakePoint(x, -rect.maxY / 2))
146146
}
147147

148-
for y in stride(from: 0, to: NSHeight(rect) / 2, by: 10)
148+
for y in stride(from: 0, to: rect.height / 2, by: 10)
149149
{
150-
graticule.move(to: NSMakePoint(NSMinX(rect), y))
151-
graticule.addLine(to: NSMakePoint(NSMaxX(rect), y))
152-
graticule.move(to: NSMakePoint(NSMinX(rect), -y))
153-
graticule.addLine(to: NSMakePoint(NSMaxX(rect), -y))
150+
graticule.move(to: NSMakePoint(rect.minX, y))
151+
graticule.addLine(to: NSMakePoint(rect.maxX, y))
152+
graticule.move(to: NSMakePoint(rect.minX, -y))
153+
graticule.addLine(to: NSMakePoint(rect.maxX, -y))
154154
}
155155

156156
graticule.strokePath()
@@ -195,7 +195,7 @@ class ScopeView: NSView
195195
scope.max = 0
196196

197197
// Move the origin
198-
bitmap.translateBy(x: 0, y: NSMidY(rect))
198+
bitmap.translateBy(x: 0, y: rect.midY)
199199

200200
// Green trace
201201
bitmap.setStrokeColor(CGColor(red: 0, green: 1, blue: 0, alpha: 1))
@@ -300,7 +300,7 @@ class ScopeView: NSView
300300
}
301301

302302
// Move the origin
303-
bitmap.translateBy(x: 0, y: -NSMidY(rect))
303+
bitmap.translateBy(x: 0, y: -rect.midY)
304304
let content = bitmap.makeImage()!
305305
context.cgContext.draw(content, in: rect)
306306
}

Scope/swift/XScaleView.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,24 @@ class XScaleView: NSView
3939
super.draw(rect)
4040

4141
// Drawing code here.
42-
let kTextSize = NSHeight(rect) / 2
42+
let kTextSize = rect.height / 2
4343

4444
// Move the origin
4545
let context = NSGraphicsContext.current!
4646
context.cgContext.translateBy(x: CGFloat(kScaleWidth), y: 0)
4747
context.shouldAntialias = false
4848

4949
// Draw scale
50-
for x in stride(from: 0, to: NSWidth(rect), by: 50)
50+
for x in stride(from: 0, to: rect.width, by: 50)
5151
{
52-
NSBezierPath.strokeLine(from: NSMakePoint(x, NSMaxY(rect) * 2 / 3),
53-
to: NSMakePoint(x, NSMaxY(rect)))
52+
NSBezierPath.strokeLine(from: NSMakePoint(x, rect.maxY * 2 / 3),
53+
to: NSMakePoint(x, rect.maxY))
5454
}
5555

56-
for x in stride(from: 0, to: NSWidth(rect), by: 10)
56+
for x in stride(from: 0, to: rect.width, by: 10)
5757
{
58-
NSBezierPath.strokeLine(from: NSMakePoint(x, NSMaxY(rect) * 3 / 4),
59-
to: NSMakePoint(x, NSMaxY(rect)))
58+
NSBezierPath.strokeLine(from: NSMakePoint(x, rect.maxY * 3 / 4),
59+
to: NSMakePoint(x, rect.maxY))
6060
}
6161

6262
context.shouldAntialias = true
@@ -68,7 +68,7 @@ class XScaleView: NSView
6868
var offset = "ms".size(withAttributes: attrs).width / 2
6969
"ms".draw(at: NSMakePoint(-offset, 4), withAttributes: attrs)
7070

71-
for x in stride(from: 100, to: NSWidth(rect), by: 100)
71+
for x in stride(from: 100, to: rect.width, by: 100)
7272
{
7373
let s =
7474
String(format: "%0.1f",
@@ -84,7 +84,7 @@ class XScaleView: NSView
8484
var offset = "sec".size(withAttributes: attrs).width / 2
8585
"sec".draw(at: NSMakePoint(-offset, 4), withAttributes: attrs)
8686

87-
for x in stride(from: 100, to: NSWidth(rect), by: 100)
87+
for x in stride(from: 100, to: rect.width, by: 100)
8888
{
8989
let s =
9090
String(format: "%0.1f",

Scope/swift/YScaleView.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,24 +57,24 @@ class YScaleView: NSView
5757

5858
// Move the origin
5959
let context = NSGraphicsContext.current!
60-
context.cgContext.translateBy(x: 0, y: NSMidY(rect))
60+
context.cgContext.translateBy(x: 0, y: rect.midY)
6161
context.shouldAntialias = false
6262

6363
// Draw scale
64-
for y in stride(from: 0, to: NSHeight(rect) / 2, by: 10)
64+
for y in stride(from: 0, to: rect.height / 2, by: 10)
6565
{
66-
NSBezierPath.strokeLine(from: NSMakePoint(NSMaxX(rect) * 2 / 3, y),
67-
to: NSMakePoint(NSMaxX(rect), y))
68-
NSBezierPath.strokeLine(from: NSMakePoint(NSMaxX(rect) * 2 / 3, -y),
69-
to: NSMakePoint(NSMaxX(rect), -y))
66+
NSBezierPath.strokeLine(from: NSMakePoint(rect.maxX * 2 / 3, y),
67+
to: NSMakePoint(rect.maxX, y))
68+
NSBezierPath.strokeLine(from: NSMakePoint(rect.maxX * 2 / 3, -y),
69+
to: NSMakePoint(rect.maxX, -y))
7070
}
7171

72-
for y in stride(from: 0, to: NSHeight(rect) / 2, by: 50)
72+
for y in stride(from: 0, to: rect.height / 2, by: 50)
7373
{
74-
NSBezierPath.strokeLine(from: NSMakePoint(NSMidX(rect), y),
75-
to: NSMakePoint(NSMaxX(rect), y))
76-
NSBezierPath.strokeLine(from: NSMakePoint(NSMidX(rect), -y),
77-
to: NSMakePoint(NSMaxX(rect), -y))
74+
NSBezierPath.strokeLine(from: NSMakePoint(rect.midX, y),
75+
to: NSMakePoint(rect.maxX, y))
76+
NSBezierPath.strokeLine(from: NSMakePoint(rect.midX, -y),
77+
to: NSMakePoint(rect.maxX, -y))
7878
}
7979

8080
// Thumb
@@ -89,9 +89,9 @@ class YScaleView: NSView
8989

9090
// Transform thumb
9191
let scale =
92-
AffineTransform(scale: NSWidth(rect) / (NSWidth(thumb.bounds) * 1.5))
92+
AffineTransform(scale: rect.width / (thumb.bounds.width * 1.5))
9393
let translate =
94-
AffineTransform(translationByX: NSWidth(rect) / 2.5,
94+
AffineTransform(translationByX: rect.width / 2.5,
9595
byY: CGFloat(yscale.index))
9696
thumb.transform(using: scale)
9797
thumb.transform(using: translate)

0 commit comments

Comments
 (0)