mirror of
https://github.com/qvacua/vimr.git
synced 2024-12-27 15:53:31 +03:00
Add emojis
This commit is contained in:
parent
e804501341
commit
bb773f46cf
@ -83,6 +83,13 @@ public class NeoVimView: NSView, NSUserInterfaceValidations {
|
|||||||
override public var acceptsFirstResponder: Bool {
|
override public var acceptsFirstResponder: Bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fileprivate static let emojis: [UInt32] = [
|
||||||
|
0x1F600...0x1F64F,
|
||||||
|
0x1F910...0x1F918,
|
||||||
|
0x1F980...0x1F984,
|
||||||
|
0x1F9C0...0x1F9C0
|
||||||
|
].flatMap { $0 }
|
||||||
|
|
||||||
fileprivate var _font = NeoVimView.defaultFont
|
fileprivate var _font = NeoVimView.defaultFont
|
||||||
|
|
||||||
@ -124,6 +131,14 @@ public class NeoVimView: NSView, NSUserInterfaceValidations {
|
|||||||
fileprivate var pinchImage = NSImage()
|
fileprivate var pinchImage = NSImage()
|
||||||
|
|
||||||
fileprivate var currentlyResizing = false
|
fileprivate var currentlyResizing = false
|
||||||
|
fileprivate var currentEmoji = "😎"
|
||||||
|
fileprivate let emojiAttrs = [
|
||||||
|
NSFontAttributeName: NSFont(name: "AppleColorEmoji", size: 72)!
|
||||||
|
]
|
||||||
|
fileprivate let resizeTextAttrs = [
|
||||||
|
NSFontAttributeName: NSFont.systemFont(ofSize: 18),
|
||||||
|
NSForegroundColorAttributeName: NSColor.darkGray
|
||||||
|
]
|
||||||
|
|
||||||
public init(frame rect: NSRect, config: Config) {
|
public init(frame rect: NSRect, config: Config) {
|
||||||
self.drawer = TextDrawer(font: self._font, useLigatures: false)
|
self.drawer = TextDrawer(font: self._font, useLigatures: false)
|
||||||
@ -298,6 +313,8 @@ extension NeoVimView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fileprivate func resizeNeoVimUiTo(size: CGSize) {
|
fileprivate func resizeNeoVimUiTo(size: CGSize) {
|
||||||
|
self.currentEmoji = self.randomEmoji()
|
||||||
|
|
||||||
// NSLog("\(#function): \(size)")
|
// NSLog("\(#function): \(size)")
|
||||||
let discreteSize = self.discreteSize(size: size)
|
let discreteSize = self.discreteSize(size: size)
|
||||||
|
|
||||||
@ -330,16 +347,21 @@ extension NeoVimView {
|
|||||||
dirtyUnionRect.fill()
|
dirtyUnionRect.fill()
|
||||||
|
|
||||||
let boundsSize = self.bounds.size
|
let boundsSize = self.bounds.size
|
||||||
|
|
||||||
|
let emojiSize = self.currentEmoji.size(withAttributes: self.emojiAttrs)
|
||||||
|
let emojiX = (boundsSize.width - emojiSize.width) / 2
|
||||||
|
let emojiY = (boundsSize.height - emojiSize.height) / 2
|
||||||
|
|
||||||
let discreteSize = self.discreteSize(size: boundsSize)
|
let discreteSize = self.discreteSize(size: boundsSize)
|
||||||
|
|
||||||
let displayStr = "\(discreteSize.width) × \(discreteSize.height)"
|
let displayStr = "\(discreteSize.width) × \(discreteSize.height)"
|
||||||
let attrs = [ NSFontAttributeName: NSFont.systemFont(ofSize: 24) ]
|
|
||||||
|
let size = displayStr.size(withAttributes: self.resizeTextAttrs)
|
||||||
let size = displayStr.size(withAttributes: attrs)
|
|
||||||
let x = (boundsSize.width - size.width) / 2
|
let x = (boundsSize.width - size.width) / 2
|
||||||
let y = (boundsSize.height - size.height) / 2
|
let y = emojiY - size.height
|
||||||
|
|
||||||
displayStr.draw(at: CGPoint(x: x, y: y), withAttributes: attrs)
|
self.currentEmoji.draw(at: CGPoint(x: emojiX, y: emojiY), withAttributes: self.emojiAttrs)
|
||||||
|
displayStr.draw(at: CGPoint(x: x, y: y), withAttributes: self.resizeTextAttrs)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -364,6 +386,15 @@ extension NeoVimView {
|
|||||||
self.drawCursor(context: context)
|
self.drawCursor(context: context)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fileprivate func randomEmoji() -> String {
|
||||||
|
let idx = Int(arc4random_uniform(UInt32(NeoVimView.emojis.count)))
|
||||||
|
guard let scalar = UnicodeScalar(NeoVimView.emojis[idx]) else {
|
||||||
|
return "😎"
|
||||||
|
}
|
||||||
|
|
||||||
|
return String(scalar)
|
||||||
|
}
|
||||||
|
|
||||||
fileprivate func draw(rowRun rowFrag: RowRun, context: CGContext) {
|
fileprivate func draw(rowRun rowFrag: RowRun, context: CGContext) {
|
||||||
// For background drawing we don't filter out the put(0, 0)s: in some cases only the put(0, 0)-cells should be
|
// For background drawing we don't filter out the put(0, 0)s: in some cases only the put(0, 0)-cells should be
|
||||||
// redrawn. => FIXME: probably we have to consider this also when drawing further down, ie when the range starts
|
// redrawn. => FIXME: probably we have to consider this also when drawing further down, ie when the range starts
|
||||||
|
Loading…
Reference in New Issue
Block a user