1
1
mirror of https://github.com/qvacua/vimr.git synced 2024-11-24 11:37:32 +03:00

GH-666 Refactor slightly

This commit is contained in:
Tae Won Ha 2018-08-29 17:17:47 +02:00
parent ce7e4e8899
commit 71fad2ebc2
6 changed files with 86 additions and 77 deletions

View File

@ -11,6 +11,7 @@
1929B2DB631E6EB5C3452B68 /* MyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1929BAF033A398BFBC2A7890 /* MyView.swift */; };
1929B30D6C4175835D1F5B21 /* MessagePackCommons.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1929B44323D6611E2927EC3B /* MessagePackCommons.swift */; };
1929B36C51BCDFCCEE974EA2 /* SwiftCommons.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1929B9C55A79D97272894F5D /* SwiftCommons.swift */; };
1929B3B70C96A78FD63DE737 /* NvimView+Debug.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1929BDC8F32F4A0D2299B5C5 /* NvimView+Debug.swift */; };
1929B40A751BDA2882D4FC94 /* NvimViewObjects.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1929B22A0CAD417EC3790F02 /* NvimViewObjects.swift */; };
1929B40C9C30B46C0E0B9DE2 /* CellAttributes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1929BE45756C88F8B43804D2 /* CellAttributes.swift */; };
1929B434DB094D61B3977390 /* TypesetterTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1929BFCCDE5C7145BE5A7387 /* TypesetterTest.swift */; };
@ -187,6 +188,7 @@
1929BBD7F88AE4F01E626691 /* NvimApiExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NvimApiExtension.swift; sourceTree = "<group>"; };
1929BD167BE7C6BB788DAE2A /* ProcessUtils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProcessUtils.swift; sourceTree = "<group>"; };
1929BD4C55D5EA933BFFB16B /* OldCellAttributes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OldCellAttributes.swift; sourceTree = "<group>"; };
1929BDC8F32F4A0D2299B5C5 /* NvimView+Debug.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NvimView+Debug.swift"; sourceTree = "<group>"; };
1929BDE2C6003A6EDC02129C /* ColorUtils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ColorUtils.swift; sourceTree = "<group>"; };
1929BE45756C88F8B43804D2 /* CellAttributes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CellAttributes.swift; sourceTree = "<group>"; };
1929BFCCDE5C7145BE5A7387 /* TypesetterTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TypesetterTest.swift; sourceTree = "<group>"; };
@ -387,6 +389,7 @@
1929BD4C55D5EA933BFFB16B /* OldCellAttributes.swift */,
1929B4355610D4E5607EAA40 /* Drawing */,
1929B2BA05AC3E1A11D6EBFC /* Commons */,
1929BDC8F32F4A0D2299B5C5 /* NvimView+Debug.swift */,
);
path = NvimView;
sourceTree = "<group>";
@ -667,6 +670,7 @@
1929BC8B14CA31C283455CF5 /* RxSwiftCommons.swift in Sources */,
1929B83EAD32DC419FEC68DB /* CocoaCommons.swift in Sources */,
1929BAB9A0399206FB7EBC76 /* CellAttributesCollection.swift in Sources */,
1929B3B70C96A78FD63DE737 /* NvimView+Debug.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@ -0,0 +1,65 @@
/**
* Tae Won Ha - http://taewon.de - @hataewon
* See LICENSE
*/
import Cocoa
#if DEBUG
extension NvimView {
private func draw(cellGridIn context: CGContext) {
context.saveGState()
defer { context.restoreGState() }
let color = NSColor.magenta.cgColor
context.setFillColor(color)
let discreteSize = self.discreteSize(size: self.bounds.size)
var lines = [
CGRect(x: 0 + self.xOffset, y: 0, width: 1, height: self.bounds.height),
CGRect(
x: self.bounds.width - 1 + self.xOffset,
y: 0,
width: 1,
height: self.bounds.height
),
CGRect(
x: 0,
y: self.bounds.height - 1 - self.yOffset,
width: self.bounds.width,
height: 1
),
CGRect(
x: 0,
y: self.bounds.height - 1 - self.yOffset
- CGFloat(discreteSize.height) * self.self.cellSize.height,
width: self.bounds.width,
height: 1
),
]
for row in 0...discreteSize.height {
for col in 0...discreteSize.width {
lines.append(contentsOf: [
CGRect(
x: CGFloat(col) * self.cellSize.width + self.xOffset - 1,
y: 0,
width: 1,
height: self.bounds.height
),
CGRect(
x: 0,
y: self.bounds.height - 1
- self.yOffset - CGFloat(row) * self.self.cellSize.height,
width: self.bounds.width,
height: 1
),
])
}
}
lines.forEach { $0.fill() }
}
}
#endif

View File

@ -12,11 +12,9 @@ extension NvimView {
}
override public func draw(_ dirtyUnionRect: NSRect) {
guard self.ugrid.hasData else {
return
}
guard self.ugrid.hasData else { return }
let context = NSGraphicsContext.current!.cgContext
guard let context = NSGraphicsContext.current?.cgContext else { return }
context.saveGState()
defer { context.restoreGState() }
@ -30,9 +28,9 @@ extension NvimView {
return
}
// When both anti-aliasing and font smoothing is turned on, then the "Use LCD font smoothing
// when available" setting is used to render texts,
// cf. chapter 11 from "Programming with Quartz".
// When both anti-aliasing and font smoothing is turned on,
// then the "Use LCD font smoothing when available" setting is used
// to render texts, cf. chapter 11 from "Programming with Quartz".
context.setShouldSmoothFonts(true);
context.setTextDrawingMode(.fill);
@ -47,61 +45,9 @@ extension NvimView {
}
// self.drawCursor(context: context)
// self.draw(cellGridIn: context)
}
private func draw(cellGridIn context: CGContext) {
context.saveGState()
defer { context.restoreGState() }
let color = NSColor.magenta.cgColor
context.setFillColor(color)
let discreteSize = self.discreteSize(size: self.bounds.size)
var lines = [
CGRect(x: 0 + self.xOffset, y: 0, width: 1, height: self.bounds.height),
CGRect(
x: self.bounds.width - 1 + self.xOffset,
y: 0,
width: 1,
height: self.bounds.height
),
CGRect(
x: 0,
y: self.bounds.height - 1 - self.yOffset,
width: self.bounds.width,
height: 1
),
CGRect(
x: 0,
y: self.bounds.height - 1 - self.yOffset
- CGFloat(discreteSize.height) * self.self.cellSize.height,
width: self.bounds.width,
height: 1
),
]
for row in 0...discreteSize.height {
for col in 0...discreteSize.width {
lines.append(contentsOf: [
CGRect(
x: CGFloat(col) * self.cellSize.width + self.xOffset - 1,
y: 0,
width: 1,
height: self.bounds.height
),
CGRect(
x: 0,
y: self.bounds.height - 1
- self.yOffset - CGFloat(row) * self.self.cellSize.height,
width: self.bounds.width,
height: 1
),
])
}
}
lines.forEach { $0.fill() }
#if DEBUG
// self.draw(cellGridIn: context)
#endif
}
private func draw(_ run: AttributesRun, in context: CGContext) {
@ -325,14 +271,6 @@ extension NvimView {
)
}
func wrapNamedKeys(_ string: String) -> String {
return "<\(string)>"
}
func vimPlainString(_ string: String) -> String {
return string.replacingOccurrences(of: "<", with: self.wrapNamedKeys("lt"))
}
func updateFontMetaData(_ newFont: NSFont) {
self.drawer.font = newFont
self.runDrawer.baseFont = newFont
@ -340,8 +278,6 @@ extension NvimView {
self.cellSize = FontUtils.cellSize(
of: newFont, linespacing: self.linespacing
)
self.descent = self.drawer.descent
self.leading = self.drawer.leading
self.resizeNeoVimUi(to: self.bounds.size)
}

View File

@ -309,4 +309,12 @@ extension NvimView {
return nil
}
func wrapNamedKeys(_ string: String) -> String {
return "<\(string)>"
}
func vimPlainString(_ string: String) -> String {
return string.replacingOccurrences(of: "<", with: self.wrapNamedKeys("lt"))
}
}

View File

@ -215,8 +215,6 @@ public class NvimView: NSView,
self.cellSize = FontUtils.cellSize(
of: self.font, linespacing: self.linespacing
)
self.descent = self.drawer.descent
self.leading = self.drawer.leading
self.api.queue = self.queue
self.bridge.stream
@ -367,8 +365,6 @@ public class NvimView: NSView,
var xOffset = CGFloat(0)
var yOffset = CGFloat(0)
var cellSize = CGSize.zero
var descent = CGFloat(0)
var leading = CGFloat(0)
var scrollGuardCounterX = 5
var scrollGuardCounterY = 5

View File

@ -80,7 +80,7 @@ class AttributesRunDrawer {
private let typesetter = Typesetter()
var cellSize: CGSize = .zero
private var cellSize: CGSize = .zero
private var baselineOffset: CGFloat = 0
private var underlinePosition: CGFloat = 0
private var underlineThickness: CGFloat = 0