@@ -592,6 +592,19 @@ - (void)drawRect:(NSRect)rect
592
592
[self batchDrawData: data];
593
593
594
594
[drawData removeAllObjects ];
595
+
596
+ CGLayerRef l = [self getLayer ];
597
+
598
+ /* during a live resize, we will have around a stale layer until the
599
+ * refresh messages travel back from the vim process. we push the old
600
+ * layer in at an offset to get rid of jitter due to lines changing position. */
601
+
602
+ CGSize layerSize = CGLayerGetSize (l);
603
+ CGSize frameSize = [self frame ].size ;
604
+ NSRect drawRect = NSMakeRect (0 , frameSize.height - layerSize.height , layerSize.width , layerSize.height );
605
+
606
+ CGContextDrawLayerInRect ([context graphicsPort ], drawRect, l);
607
+
595
608
}
596
609
597
610
- (void )performBatchDrawWithData : (NSData *)data
@@ -605,6 +618,33 @@ - (void)performBatchDrawWithData:(NSData *)data
605
618
[self display ];
606
619
}
607
620
621
+ - (void )releaseLayer
622
+ {
623
+ if (layer) {
624
+ CGLayerRelease (layer);
625
+ layer = nil ;
626
+ layerContext = nil ;
627
+ }
628
+ }
629
+ - (CGLayerRef )getLayer
630
+ {
631
+ if (!layer) {
632
+ NSGraphicsContext *context = [NSGraphicsContext currentContext ];
633
+ NSRect frame = [self frame ];
634
+ layer = CGLayerCreateWithContext ([context graphicsPort ], frame.size , NULL );
635
+ }
636
+ return layer;
637
+ }
638
+
639
+ - (CGContextRef )getLayerContext
640
+ {
641
+ if (!layerContext)
642
+ layerContext = CGLayerGetContext ([self getLayer ]);
643
+
644
+ return layerContext;
645
+ }
646
+
647
+
608
648
- (NSSize )constrainRows : (int *)rows columns : (int *)cols toSize : (NSSize )size
609
649
{
610
650
// TODO:
@@ -852,7 +892,7 @@ - (void)batchDrawData:(NSData *)data
852
892
const void *end = bytes + [data length ];
853
893
854
894
#if MM_DEBUG_DRAWING
855
- ASLogNotice (@" ====> BEGIN %s " , _cmd );
895
+ ASLogNotice (@" ====> BEGIN" );
856
896
#endif
857
897
// TODO: Sanity check input
858
898
@@ -908,10 +948,13 @@ - (void)batchDrawData:(NSData *)data
908
948
column: col
909
949
numRows: height
910
950
numColumns: width];
911
- [signImg drawInRect: r
912
- fromRect: NSZeroRect
913
- operation: NSCompositingOperationSourceOver
914
- fraction: 1.0 ];
951
+
952
+ CGContextRef context = [self getLayerContext ];
953
+ CGImageRef cgImage = [signImg CGImageForProposedRect: &r
954
+ context: nil
955
+ hints: nil ];
956
+
957
+ CGContextDrawImage (context, r, cgImage);
915
958
} else if (DrawStringDrawType == type) {
916
959
int bg = *((int *)bytes); bytes += sizeof (int );
917
960
int fg = *((int *)bytes); bytes += sizeof (int );
@@ -1013,7 +1056,7 @@ - (void)batchDrawData:(NSData *)data
1013
1056
}
1014
1057
1015
1058
#if MM_DEBUG_DRAWING
1016
- ASLogNotice (@" <==== END %s " , _cmd );
1059
+ ASLogNotice (@" <==== END" );
1017
1060
#endif
1018
1061
}
1019
1062
@@ -1294,7 +1337,7 @@ - (void)drawString:(const UniChar *)chars length:(UniCharCount)length
1294
1337
withFlags : (int )flags foregroundColor : (int )fg
1295
1338
backgroundColor : (int )bg specialColor : (int )sp
1296
1339
{
1297
- CGContextRef context = [[ NSGraphicsContext currentContext ] graphicsPort ];
1340
+ CGContextRef context = [self getLayerContext ];
1298
1341
NSRect frame = [self bounds ];
1299
1342
float x = col*cellSize.width + insetSize.width ;
1300
1343
float y = frame.size .height - insetSize.height - (1 +row)*cellSize.height ;
@@ -1412,8 +1455,16 @@ - (void)drawString:(const UniChar *)chars length:(UniCharCount)length
1412
1455
1413
1456
- (void )scrollRect : (NSRect )rect lineCount : (int )count
1414
1457
{
1415
- NSSize delta={0 , -count * cellSize.height };
1416
- [self scrollRect: rect by: delta];
1458
+ CGContextRef context = [self getLayerContext ];
1459
+ int yOffset = count * cellSize.height ;
1460
+ NSRect clipRect = rect;
1461
+ clipRect.origin .y -= yOffset;
1462
+
1463
+ /* draw self on top of self, offset so as to "scroll" lines vertically. */
1464
+ CGContextSaveGState (context);
1465
+ CGContextClipToRect (context, clipRect);
1466
+ CGContextDrawLayerAtPoint (context, CGPointMake (0 , -yOffset), [self getLayer ]);
1467
+ CGContextRestoreGState (context);
1417
1468
}
1418
1469
1419
1470
- (void )deleteLinesFromRow : (int )row lineCount : (int )count
@@ -1455,7 +1506,7 @@ - (void)insertLinesAtRow:(int)row lineCount:(int)count
1455
1506
- (void )clearBlockFromRow : (int )row1 column : (int )col1 toRow : (int )row2
1456
1507
column : (int )col2 color : (int )color
1457
1508
{
1458
- CGContextRef context = [[ NSGraphicsContext currentContext ] graphicsPort ];
1509
+ CGContextRef context = [self getLayerContext ];
1459
1510
NSRect rect = [self rectFromRow: row1 column: col1 toRow: row2 column: col2];
1460
1511
1461
1512
CGContextSetRGBFillColor (context, RED (color), GREEN (color), BLUE (color),
@@ -1468,7 +1519,8 @@ - (void)clearBlockFromRow:(int)row1 column:(int)col1 toRow:(int)row2
1468
1519
1469
1520
- (void )clearAll
1470
1521
{
1471
- CGContextRef context = [[NSGraphicsContext currentContext ] graphicsPort ];
1522
+ [self releaseLayer ];
1523
+ CGContextRef context = [self getLayerContext ];
1472
1524
NSRect rect = [self bounds ];
1473
1525
float r = [defaultBackgroundColor redComponent ];
1474
1526
float g = [defaultBackgroundColor greenComponent ];
@@ -1484,7 +1536,7 @@ - (void)clearAll
1484
1536
- (void )drawInsertionPointAtRow : (int )row column : (int )col shape : (int )shape
1485
1537
fraction : (int )percent color : (int )color
1486
1538
{
1487
- CGContextRef context = [[ NSGraphicsContext currentContext ] graphicsPort ];
1539
+ CGContextRef context = [self getLayerContext ];
1488
1540
NSRect rect = [self rectForRow: row column: col numRows: 1 numColumns: 1 ];
1489
1541
1490
1542
CGContextSaveGState (context);
@@ -1533,7 +1585,7 @@ - (void)drawInvertedRectAtRow:(int)row column:(int)col numRows:(int)nrows
1533
1585
numColumns : (int )ncols
1534
1586
{
1535
1587
// TODO: THIS CODE HAS NOT BEEN TESTED!
1536
- CGContextRef cgctx = [[ NSGraphicsContext currentContext ] graphicsPort ];
1588
+ CGContextRef cgctx = [self getLayerContext ];
1537
1589
CGContextSaveGState (cgctx);
1538
1590
CGContextSetBlendMode (cgctx, kCGBlendModeDifference );
1539
1591
CGContextSetRGBFillColor (cgctx, 1.0 , 1.0 , 1.0 , 1.0 );
0 commit comments