mirror of
https://github.com/qvacua/vimr.git
synced 2024-12-28 08:13:17 +03:00
GH-371 Revert to old method: set needs display for each put and cache colors and use SRGB color space throughout
- sometimes flush is not called by neovim after puts
This commit is contained in:
parent
1b005e4862
commit
bc16077849
@ -5,13 +5,22 @@
|
||||
|
||||
import Cocoa
|
||||
|
||||
fileprivate var colorCache = [UInt32: NSColor]()
|
||||
|
||||
class ColorUtils {
|
||||
|
||||
static func colorIgnoringAlpha(_ rgb: UInt32) -> NSColor {
|
||||
if let color = colorCache[rgb] {
|
||||
return color
|
||||
}
|
||||
|
||||
let red = (CGFloat((rgb >> 16) & 0xFF)) / 255.0;
|
||||
let green = (CGFloat((rgb >> 8) & 0xFF)) / 255.0;
|
||||
let blue = (CGFloat((rgb ) & 0xFF)) / 255.0;
|
||||
|
||||
return NSColor(srgbRed: red, green: green, blue: blue, alpha: 1.0)
|
||||
let color = NSColor(srgbRed: red, green: green, blue: blue, alpha: 1.0)
|
||||
colorCache[rgb] = color
|
||||
|
||||
return color
|
||||
}
|
||||
}
|
||||
|
@ -166,7 +166,7 @@ public class NeoVimView: NSView, NeoVimUiBridgeProtocol, NSUserInterfaceValidati
|
||||
NSForegroundColorAttributeName: NSColor.darkGray
|
||||
]
|
||||
|
||||
fileprivate var rectsMarkedForRender = [CGRect]()
|
||||
fileprivate let colorSpace = NSColorSpace.sRGB
|
||||
|
||||
public init(frame rect: NSRect, config: Config) {
|
||||
self.drawer = TextDrawer(font: self._font)
|
||||
@ -202,6 +202,10 @@ public class NeoVimView: NSView, NeoVimUiBridgeProtocol, NSUserInterfaceValidati
|
||||
}
|
||||
}
|
||||
|
||||
override public func viewDidMoveToWindow() {
|
||||
self.window?.colorSpace = self.colorSpace
|
||||
}
|
||||
|
||||
convenience override init(frame rect: NSRect) {
|
||||
self.init(frame: rect, config: Config(useInteractiveZsh: false))
|
||||
}
|
||||
@ -1404,14 +1408,6 @@ extension NeoVimView {
|
||||
}
|
||||
|
||||
public func flush() {
|
||||
if self.rectsMarkedForRender.isEmpty {
|
||||
return
|
||||
}
|
||||
|
||||
DispatchUtils.gui {
|
||||
self.rectsMarkedForRender.forEach(self.setNeedsDisplay)
|
||||
self.rectsMarkedForRender.removeAll()
|
||||
}
|
||||
}
|
||||
|
||||
public func updateForeground(_ fg: Int32) {
|
||||
@ -1560,14 +1556,14 @@ extension NeoVimView {
|
||||
}
|
||||
|
||||
fileprivate func markForRenderWholeView() {
|
||||
self.rectsMarkedForRender.append(self.bounds)
|
||||
self.needsDisplay = true
|
||||
}
|
||||
|
||||
fileprivate func markForRender(region: Region) {
|
||||
self.rectsMarkedForRender.append(self.regionRectFor(region: region))
|
||||
self.setNeedsDisplay(self.regionRectFor(region: region))
|
||||
}
|
||||
|
||||
fileprivate func markForRender(row: Int, column: Int) {
|
||||
self.rectsMarkedForRender.append(self.cellRectFor(row: row, column: column))
|
||||
self.setNeedsDisplay(self.cellRectFor(row: row, column: column))
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,19 @@
|
||||
#define GREEN(color_code) (((color_code >> 8) & 0xff) / 255.0f)
|
||||
#define BLUE(color_code) (((color_code ) & 0xff) / 255.0f)
|
||||
|
||||
static dispatch_once_t token;
|
||||
static NSMutableDictionary *colorCache;
|
||||
|
||||
static CGColorRef color_for(unsigned int value) {
|
||||
NSColor *color = colorCache[@(value)];
|
||||
if (color == nil) {
|
||||
color = [NSColor colorWithSRGBRed:RED(value) green:GREEN(value) blue:BLUE(value) alpha:1];
|
||||
colorCache[@(value)] = color;
|
||||
}
|
||||
|
||||
return color.CGColor;
|
||||
}
|
||||
|
||||
@implementation TextDrawer {
|
||||
NSLayoutManager *_layoutManager;
|
||||
|
||||
@ -55,6 +68,10 @@
|
||||
}
|
||||
|
||||
- (instancetype _Nonnull)initWithFont:(NSFont *_Nonnull)font {
|
||||
dispatch_once (&token, ^{
|
||||
colorCache = [[NSMutableDictionary alloc] init];
|
||||
});
|
||||
|
||||
self = [super init];
|
||||
if (self == nil) {
|
||||
return nil;
|
||||
@ -111,7 +128,7 @@
|
||||
color:(unsigned int)color
|
||||
context:(CGContextRef _Nonnull)context
|
||||
{
|
||||
CGContextSetRGBFillColor(context, RED(color), GREEN(color), BLUE(color), ALPHA(color));
|
||||
CGContextSetFillColorWithColor(context, color_for(color));
|
||||
CGRect rect = {
|
||||
{positions[0].x, positions[0].y + _underlinePosition},
|
||||
{positions[0].x + positions[count - 1].x + _cellSize.width, _underlineThickness}
|
||||
@ -139,7 +156,7 @@
|
||||
CGGlyph *glyphs = malloc(unilength * sizeof(CGGlyph));
|
||||
CTFontRef fontWithTraits = [self fontWithTrait:fontTrait];
|
||||
|
||||
CGContextSetRGBFillColor(context, RED(foreground), GREEN(foreground), BLUE(foreground), 1.0);
|
||||
CGContextSetFillColorWithColor(context, color_for(foreground));
|
||||
recurseDraw(unichars, glyphs, positions, unilength, context, fontWithTraits, _fontLookupCache, _usesLigatures);
|
||||
|
||||
CFRelease(fontWithTraits);
|
||||
|
Loading…
Reference in New Issue
Block a user